elm-matrix-sdk-beta/tests/Test/Values/Room.elm

106 lines
3.3 KiB
Elm
Raw Normal View History

2024-04-24 09:12:46 +00:00
module Test.Values.Room exposing (..)
2024-04-26 09:31:35 +00:00
import Expect
2024-04-24 09:12:46 +00:00
import Fuzz exposing (Fuzzer)
import Internal.Values.Room as Room exposing (Room)
import Json.Decode as D
2024-04-26 09:31:35 +00:00
import Json.Encode as E
import Test exposing (..)
import Test.Filter.Timeline as TestFilter
import Test.Values.Event as TestEvent
2024-04-24 09:12:46 +00:00
placeholderValue : E.Value
2024-04-26 09:31:35 +00:00
placeholderValue =
E.string "foo bar baz"
2024-04-24 09:12:46 +00:00
fuzzer : Fuzzer Room
fuzzer =
Fuzz.string
|> Fuzz.map Room.init
|> addAFewTimes Fuzz.string (\key -> Room.setAccountData key placeholderValue)
|> addAFewTimes (Fuzz.list TestEvent.fuzzer) Room.addEvents
2024-04-26 09:31:35 +00:00
|> add4AFewTimes (Fuzz.list TestEvent.fuzzer)
TestFilter.fuzzer
(Fuzz.maybe Fuzz.string)
Fuzz.string
2024-04-24 09:12:46 +00:00
(\a b c d ->
Room.Batch a b c d
|> Room.addBatch
)
2024-04-26 09:31:35 +00:00
|> add4AFewTimes (Fuzz.list TestEvent.fuzzer)
TestFilter.fuzzer
(Fuzz.maybe Fuzz.string)
Fuzz.string
2024-04-24 09:12:46 +00:00
(\a b c d ->
Room.Batch a b c d
|> Room.addSync
)
2024-04-26 09:31:35 +00:00
2024-04-24 09:12:46 +00:00
addAFewTimes : Fuzzer a -> (a -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
addAFewTimes fuzz f roomFuzzer =
Fuzz.map2
(\items room -> List.foldl f room items)
(Fuzz.list fuzz)
roomFuzzer
2024-04-26 09:31:35 +00:00
2024-04-24 09:12:46 +00:00
add2AFewTimes : Fuzzer a -> Fuzzer b -> (a -> b -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
add2AFewTimes fuzz1 fuzz2 f roomFuzzer =
Fuzz.map2
2024-04-26 09:31:35 +00:00
(\items room -> List.foldl (\( a, b ) -> f a b) room items)
(Fuzz.list <| Fuzz.pair fuzz1 fuzz2)
2024-04-24 09:12:46 +00:00
roomFuzzer
2024-04-26 09:31:35 +00:00
2024-04-24 09:12:46 +00:00
add3AFewTimes : Fuzzer a -> Fuzzer b -> Fuzzer c -> (a -> b -> c -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
add3AFewTimes fuzz1 fuzz2 fuzz3 f roomFuzzer =
Fuzz.map2
2024-04-26 09:31:35 +00:00
(\items room -> List.foldl (\( a, b, c ) -> f a b c) room items)
(Fuzz.list <| Fuzz.triple fuzz1 fuzz2 fuzz3)
2024-04-24 09:12:46 +00:00
roomFuzzer
2024-04-26 09:31:35 +00:00
2024-04-24 09:12:46 +00:00
add4AFewTimes : Fuzzer a -> Fuzzer b -> Fuzzer c -> Fuzzer d -> (a -> b -> c -> d -> Room -> Room) -> Fuzzer Room -> Fuzzer Room
add4AFewTimes fuzz1 fuzz2 fuzz3 fuzz4 f roomFuzzer =
Fuzz.map2
2024-04-26 09:31:35 +00:00
(\items room -> List.foldl (\( ( a, b ), ( c, d ) ) -> f a b c d) room items)
(Fuzz.list <| Fuzz.pair (Fuzz.pair fuzz1 fuzz2) (Fuzz.pair fuzz3 fuzz4))
2024-04-24 09:12:46 +00:00
roomFuzzer
2024-04-26 09:31:35 +00:00
2024-04-24 09:12:46 +00:00
suite : Test
suite =
describe "Room"
2024-04-26 09:31:35 +00:00
[ fuzz3 fuzzer
Fuzz.string
Fuzz.string
"JSON Account Data can be overridden"
2024-04-24 09:12:46 +00:00
(\room key text ->
room
|> Room.setAccountData key (E.string text)
|> Room.getAccountData key
|> Maybe.map (D.decodeValue D.string)
|> Maybe.andThen Result.toMaybe
|> Expect.equal (Just text)
)
2024-04-26 09:31:35 +00:00
, fuzz fuzzer
"Room -> JSON -> Room is equal"
(\room ->
let
value : E.Value
value =
Room.encode room
in
value
2024-04-26 09:31:35 +00:00
|> D.decodeValue Room.decode
|> Result.toMaybe
|> Maybe.map Tuple.first
|> Maybe.map Room.encode
|> Maybe.map (E.encode 0)
|> Expect.equal (Just <| E.encode 0 value)
2024-04-26 09:31:35 +00:00
)
2024-04-24 09:12:46 +00:00
]