Add Event tests
parent
ff180ec84d
commit
5065ed05ff
|
@ -1,7 +1,7 @@
|
|||
module Internal.Values.Event exposing
|
||||
( Event
|
||||
, content, eventId, eventType, originServerTs, roomId, sender, stateKey
|
||||
, UnsignedData, age, prevContent, redactedBecause, transactionId
|
||||
, UnsignedData(..), age, prevContent, redactedBecause, transactionId
|
||||
, encode, decoder
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
module Event exposing (..)
|
||||
|
||||
import Expect
|
||||
import Fuzz exposing (Fuzzer)
|
||||
import Iddict as TestIddict
|
||||
import Internal.Tools.Iddict as Iddict
|
||||
import Internal.Tools.Timestamp as Timestamp
|
||||
import Internal.Values.Envelope as Envelope
|
||||
import Internal.Values.Event as Event
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import Test exposing (..)
|
||||
import Timestamp as TestTimestamp
|
||||
|
||||
|
||||
{-| Example values that can be used for arbitrary JSON values
|
||||
-}
|
||||
valueFuzzer : Fuzzer E.Value
|
||||
valueFuzzer =
|
||||
Fuzz.oneOf
|
||||
[ Fuzz.map (Iddict.encode E.int) (TestIddict.fuzzer Fuzz.int)
|
||||
, Fuzz.map Timestamp.encode TestTimestamp.fuzzer
|
||||
, 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))
|
||||
]
|
||||
|
||||
|
||||
fuzzer : Fuzzer Event.Event
|
||||
fuzzer =
|
||||
Fuzz.map8
|
||||
(\c ei et o r se sk u ->
|
||||
Envelope.init
|
||||
{ content = c
|
||||
, eventId = ei
|
||||
, eventType = et
|
||||
, originServerTs = o
|
||||
, roomId = r
|
||||
, sender = se
|
||||
, stateKey = sk
|
||||
, unsigned = u
|
||||
}
|
||||
)
|
||||
valueFuzzer
|
||||
Fuzz.string
|
||||
Fuzz.string
|
||||
TestTimestamp.fuzzer
|
||||
Fuzz.string
|
||||
Fuzz.string
|
||||
(Fuzz.maybe Fuzz.string)
|
||||
(Fuzz.maybe unsignedDataFuzzer)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
json : Test
|
||||
json =
|
||||
describe "JSON tests"
|
||||
[ fuzz fuzzer
|
||||
"JSON encode + JSON decode"
|
||||
(\event ->
|
||||
event
|
||||
|> Event.encode
|
||||
|> D.decodeValue Event.decoder
|
||||
|> Expect.equal (Ok event)
|
||||
)
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
module Timestamp exposing (..)
|
||||
|
||||
import Fuzz exposing (Fuzzer)
|
||||
import Internal.Tools.Timestamp exposing (Timestamp)
|
||||
import Test exposing (..)
|
||||
import Time
|
||||
|
||||
|
||||
fuzzer : Fuzzer Timestamp
|
||||
fuzzer =
|
||||
Fuzz.map Time.millisToPosix Fuzz.int
|
Loading…
Reference in New Issue