2023-12-24 01:16:52 +00:00
|
|
|
module Test.Values.Event exposing (..)
|
|
|
|
|
2024-01-04 02:13:17 +00:00
|
|
|
import Expect
|
2023-12-24 01:16:52 +00:00
|
|
|
import Fuzz exposing (Fuzzer)
|
|
|
|
import Internal.Values.Event as Event exposing (Event)
|
|
|
|
import Json.Encode as E
|
|
|
|
import Test exposing (..)
|
2024-04-12 11:57:38 +00:00
|
|
|
import Test.Grammar.UserId as UserId
|
2023-12-24 01:16:52 +00:00
|
|
|
import Test.Tools.Timestamp as TestTimestamp
|
|
|
|
|
|
|
|
|
|
|
|
fuzzer : Fuzzer Event
|
|
|
|
fuzzer =
|
|
|
|
Fuzz.map8 Event
|
|
|
|
valueFuzzer
|
|
|
|
Fuzz.string
|
|
|
|
TestTimestamp.fuzzer
|
|
|
|
Fuzz.string
|
2024-04-12 11:57:38 +00:00
|
|
|
UserId.fullUserFuzzer
|
2023-12-24 01:16:52 +00:00
|
|
|
(Fuzz.maybe Fuzz.string)
|
|
|
|
Fuzz.string
|
|
|
|
(Fuzz.maybe unsignedDataFuzzer)
|
|
|
|
|
2023-12-29 13:58:50 +00:00
|
|
|
|
2023-12-29 13:50:43 +00:00
|
|
|
{-| Fuzzer for an event with a set state key
|
|
|
|
-}
|
|
|
|
fuzzerState : Fuzzer Event
|
|
|
|
fuzzerState =
|
|
|
|
Fuzz.map2
|
|
|
|
(\event default ->
|
|
|
|
{ event
|
2023-12-29 13:58:50 +00:00
|
|
|
| stateKey =
|
|
|
|
event.stateKey
|
|
|
|
|> Maybe.withDefault default
|
|
|
|
|> Maybe.Just
|
2023-12-29 13:50:43 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
|
2023-12-24 01:16:52 +00:00
|
|
|
|
|
|
|
unsignedDataFuzzer : Fuzzer Event.UnsignedData
|
|
|
|
unsignedDataFuzzer =
|
|
|
|
Fuzz.map4
|
|
|
|
(\age prev redact trans ->
|
|
|
|
Event.UnsignedData
|
|
|
|
{ age = age
|
|
|
|
, prevContent = prev
|
|
|
|
, redactedBecause = redact
|
|
|
|
, transactionId = trans
|
|
|
|
}
|
|
|
|
)
|
|
|
|
(Fuzz.maybe Fuzz.int)
|
|
|
|
(Fuzz.maybe valueFuzzer)
|
|
|
|
(Fuzz.maybe <| Fuzz.lazy (\_ -> fuzzer))
|
|
|
|
(Fuzz.maybe Fuzz.string)
|
|
|
|
|
|
|
|
|
|
|
|
{-| Example values that can be used for arbitrary JSON values
|
|
|
|
-}
|
|
|
|
valueFuzzer : Fuzzer E.Value
|
|
|
|
valueFuzzer =
|
|
|
|
Fuzz.oneOf
|
|
|
|
[ Fuzz.map E.int Fuzz.int
|
|
|
|
, Fuzz.map E.string Fuzz.string
|
|
|
|
, Fuzz.map (E.list E.int) (Fuzz.list Fuzz.int)
|
|
|
|
, Fuzz.map (E.list E.string) (Fuzz.list Fuzz.string)
|
|
|
|
, Fuzz.map Event.encode (Fuzz.lazy (\_ -> fuzzer))
|
|
|
|
]
|
2024-01-04 01:00:31 +00:00
|
|
|
|
2024-01-04 02:13:17 +00:00
|
|
|
|
2024-01-04 01:00:31 +00:00
|
|
|
suite : Test
|
|
|
|
suite =
|
|
|
|
describe "Sanity check"
|
2024-01-04 02:13:17 +00:00
|
|
|
[ fuzz fuzzer
|
|
|
|
"event = event"
|
2024-01-04 01:00:31 +00:00
|
|
|
(\event ->
|
|
|
|
Event.isEqual event event
|
|
|
|
|> Expect.equal True
|
|
|
|
)
|
|
|
|
]
|