Fix Event test

This commit is starting to show how the definition of the Envelope wrapper is better done on a different level
3-event
Bram 2023-12-24 00:37:22 +01:00
parent 1a819cbe39
commit 5ac3e7eb6a
5 changed files with 64 additions and 16 deletions

View File

@ -1,5 +1,5 @@
module Internal.Values.Envelope exposing
( Envelope, init
( Envelope(..), init
, map, mapMaybe, mapList
, Settings, mapSettings, extractSettings
, mapContext

View File

@ -3,6 +3,7 @@ module Internal.Values.Event exposing
, content, eventId, eventType, originServerTs, roomId, sender, stateKey
, UnsignedData(..), age, prevContent, redactedBecause, transactionId
, encode, decoder
, IEvent
)
{-|

View File

@ -1,6 +1,6 @@
module Matrix.Event exposing
( Event, content, eventType, stateKey
, eventId, originServerTs, roomId, sender
, eventId, roomId, sender, originServerTs
, previousContent, redactedBecause
)
@ -20,7 +20,7 @@ events.
## Metadata
@docs eventId, originServerTs, roomId, sender
@docs eventId, roomId, sender, originServerTs
## Optional data

42
tests/Envelope.elm Normal file
View File

@ -0,0 +1,42 @@
module Envelope exposing (..)
import Context as TestContext
import Fuzz exposing (Fuzzer)
import Internal.Config.Default as Default
import Internal.Values.Envelope exposing (Envelope(..), Settings)
import Test exposing (..)
fuzzer : Fuzzer a -> Fuzzer (Envelope a)
fuzzer fuzz =
Fuzz.map3
(\content context settings ->
Envelope
{ content = content
, context = context
, settings = settings
}
)
fuzz
TestContext.fuzzer
fuzzerSettings
fuzzerSettings : Fuzzer Settings
fuzzerSettings =
Fuzz.map3 Settings
(Fuzz.oneOf
[ Fuzz.constant Default.currentVersion
, Fuzz.string
]
)
(Fuzz.oneOf
[ Fuzz.constant Default.deviceName
, Fuzz.string
]
)
(Fuzz.oneOf
[ Fuzz.constant Default.syncTime
, Fuzz.int
]
)

View File

@ -1,5 +1,6 @@
module Event exposing (..)
import Envelope as TestEnvelope
import Expect
import Fuzz exposing (Fuzzer)
import Iddict as TestIddict
@ -24,15 +25,14 @@ valueFuzzer =
, 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))
, Fuzz.map Event.encode (Fuzz.lazy (\_ -> TestEnvelope.fuzzer fuzzer))
]
fuzzer : Fuzzer Event.Event
fuzzer : Fuzzer Event.IEvent
fuzzer =
Fuzz.map8
(\c ei et o r se sk u ->
Envelope.init
{ content = c
, eventId = ei
, eventType = et
@ -53,6 +53,11 @@ fuzzer =
(Fuzz.maybe unsignedDataFuzzer)
fuzzerFull : Fuzzer Event.Event
fuzzerFull =
TestEnvelope.fuzzer fuzzer
unsignedDataFuzzer : Fuzzer Event.UnsignedData
unsignedDataFuzzer =
Fuzz.map4
@ -73,7 +78,7 @@ unsignedDataFuzzer =
json : Test
json =
describe "JSON tests"
[ fuzz fuzzer
[ fuzz fuzzerFull
"JSON encode + JSON decode"
(\event ->
event