2024-04-24 09:12:46 +00:00
|
|
|
module Test.Values.Room exposing (..)
|
|
|
|
|
|
|
|
import Fuzz exposing (Fuzzer)
|
|
|
|
import Internal.Values.Room as Room exposing (Room)
|
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)
|
2024-05-30 21:15:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- |> addAFewTimes (Fuzz.list TestEvent.fuzzer) Room.addEvents
|
|
|
|
-- |> add4AFewTimes (Fuzz.list TestEvent.fuzzer)
|
|
|
|
-- TestFilter.fuzzer
|
|
|
|
-- (Fuzz.maybe Fuzz.string)
|
|
|
|
-- Fuzz.string
|
|
|
|
-- (\a b c d ->
|
|
|
|
-- Room.Batch a b c d
|
|
|
|
-- |> Room.addBatch
|
|
|
|
-- )
|
|
|
|
-- |> add4AFewTimes (Fuzz.list TestEvent.fuzzer)
|
|
|
|
-- TestFilter.fuzzer
|
|
|
|
-- (Fuzz.maybe Fuzz.string)
|
|
|
|
-- Fuzz.string
|
|
|
|
-- (\a b c d ->
|
|
|
|
-- Room.Batch a b c d
|
|
|
|
-- |> Room.addSync
|
|
|
|
-- )
|
2024-04-24 09:12:46 +00:00
|
|
|
|
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-26 13:44:01 +00:00
|
|
|
|
2024-04-26 13:29:04 +00:00
|
|
|
-- suite : Test
|
|
|
|
-- suite =
|
|
|
|
-- describe "Room"
|
|
|
|
-- [ fuzz3 fuzzer
|
|
|
|
-- Fuzz.string
|
|
|
|
-- Fuzz.string
|
|
|
|
-- "JSON Account Data can be overridden"
|
|
|
|
-- (\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)
|
|
|
|
-- )
|
|
|
|
-- , fuzz fuzzer
|
|
|
|
-- "Room -> JSON -> Room is equal"
|
|
|
|
-- (\room ->
|
|
|
|
-- let
|
|
|
|
-- value : E.Value
|
|
|
|
-- value =
|
|
|
|
-- Room.encode room
|
|
|
|
-- in
|
|
|
|
-- value
|
|
|
|
-- |> 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)
|
|
|
|
-- )
|
|
|
|
-- ]
|