Add Timestamp test

3-event
Bram 2023-12-24 11:17:43 +01:00
parent 959642499b
commit bf64d5911f
2 changed files with 58 additions and 4 deletions

View File

@ -6,9 +6,8 @@ module Internal.Values.Vault exposing (Vault)
-} -}
import Internal.Values.Envelope as Envelope
{-| This is the Vault type. {-| This is the Vault type.
-} -}
type alias Vault = () type alias Vault =
()

View File

@ -1,7 +1,10 @@
module Test.Tools.Timestamp exposing (..) module Test.Tools.Timestamp exposing (..)
import Expect
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)
import Internal.Tools.Timestamp exposing (Timestamp) import Internal.Tools.Timestamp as Timestamp exposing (Timestamp)
import Json.Decode as D
import Json.Encode as E
import Test exposing (..) import Test exposing (..)
import Time import Time
@ -9,3 +12,55 @@ import Time
fuzzer : Fuzzer Timestamp fuzzer : Fuzzer Timestamp
fuzzer = fuzzer =
Fuzz.map Time.millisToPosix Fuzz.int Fuzz.map Time.millisToPosix Fuzz.int
suite : Test
suite =
describe "Timestamp"
[ describe "JSON"
[ fuzz2 fuzzer
Fuzz.int
"JSON encode -> JSON decode"
(\time indent ->
time
|> Timestamp.encode
|> E.encode indent
|> D.decodeString Timestamp.decoder
|> Expect.equal (Ok time)
)
, fuzz fuzzer
"JSON decode -> millis"
(\time ->
time
|> Timestamp.encode
|> D.decodeValue D.int
|> Expect.equal (Ok <| Time.posixToMillis time)
)
, fuzz Fuzz.int
"JSON decode -> time"
(\n ->
n
|> E.int
|> D.decodeValue Timestamp.decoder
|> Expect.equal (Ok <| Time.millisToPosix n)
)
]
, describe "Identity"
[ fuzz fuzzer
"Posix -> int -> Posix"
(\time ->
time
|> Time.posixToMillis
|> Time.millisToPosix
|> Expect.equal time
)
, fuzz Fuzz.int
"int -> Posix -> int"
(\n ->
n
|> Time.millisToPosix
|> Time.posixToMillis
|> Expect.equal n
)
]
]