2023-12-24 01:16:52 +00:00
|
|
|
module Test.Values.Context exposing (..)
|
2023-12-21 22:16:21 +00:00
|
|
|
|
|
|
|
import Expect
|
|
|
|
import Fuzz exposing (Fuzzer)
|
|
|
|
import Internal.Config.Leaks as Leaks
|
2024-05-27 14:39:50 +00:00
|
|
|
import Internal.Tools.Hashdict as Hashdict
|
|
|
|
import Internal.Values.Context as Context exposing (Context, Versions)
|
2023-12-21 22:16:21 +00:00
|
|
|
import Json.Decode as D
|
2023-12-21 22:17:34 +00:00
|
|
|
import Json.Encode as E
|
2024-05-27 14:39:50 +00:00
|
|
|
import Set
|
2023-12-21 22:17:34 +00:00
|
|
|
import Test exposing (..)
|
2024-05-27 14:39:50 +00:00
|
|
|
import Test.Tools.Timestamp as TestTimestamp
|
2023-12-21 22:16:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
fuzzer : Fuzzer Context
|
|
|
|
fuzzer =
|
|
|
|
let
|
|
|
|
maybeString : Fuzzer (Maybe String)
|
|
|
|
maybeString =
|
|
|
|
Fuzz.maybe Fuzz.string
|
|
|
|
in
|
2024-05-28 16:29:26 +00:00
|
|
|
Fuzz.map8 (\a b c d e ( f, g ) ( h, i ) ( j, k ) -> Context a b c d e f g h i j k)
|
2024-05-27 14:39:50 +00:00
|
|
|
(Fuzz.constant <| Hashdict.empty .value)
|
2023-12-21 22:17:34 +00:00
|
|
|
maybeString
|
|
|
|
maybeString
|
2024-05-27 14:39:50 +00:00
|
|
|
(Fuzz.maybe TestTimestamp.fuzzer)
|
2023-12-21 22:17:34 +00:00
|
|
|
maybeString
|
2024-05-27 14:39:50 +00:00
|
|
|
(Fuzz.pair
|
2024-05-28 16:29:26 +00:00
|
|
|
maybeString
|
2024-05-27 14:39:50 +00:00
|
|
|
Fuzz.string
|
2024-05-28 16:29:26 +00:00
|
|
|
)
|
|
|
|
(Fuzz.pair
|
|
|
|
maybeString
|
2024-05-27 14:39:50 +00:00
|
|
|
maybeString
|
|
|
|
)
|
|
|
|
(Fuzz.pair
|
|
|
|
maybeString
|
|
|
|
(Fuzz.maybe <| versionsFuzzer)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
versionsFuzzer : Fuzzer Versions
|
|
|
|
versionsFuzzer =
|
|
|
|
Fuzz.map2 Versions
|
|
|
|
(Fuzz.list Fuzz.string)
|
|
|
|
(Fuzz.map Set.fromList <| Fuzz.list Fuzz.string)
|
2023-12-21 22:17:34 +00:00
|
|
|
|
2023-12-21 22:16:21 +00:00
|
|
|
|
|
|
|
{-| If a leak is spotted, make sure to change the leaking value and then test
|
|
|
|
with the same seed to ensure it is not a (tiny) coincidence and a leak is in
|
|
|
|
fact coming through.
|
|
|
|
-}
|
|
|
|
leaks : Test
|
|
|
|
leaks =
|
|
|
|
describe "No leaks allowed"
|
2023-12-21 22:17:34 +00:00
|
|
|
[ fuzz2 fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
"Access token"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setAccessToken value
|
|
|
|
|> Context.getAccessToken
|
|
|
|
|> Expect.notEqual Leaks.accessToken
|
|
|
|
)
|
2023-12-21 22:17:34 +00:00
|
|
|
, fuzz2 fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
"Base URL"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setBaseUrl value
|
|
|
|
|> Context.getBaseUrl
|
|
|
|
|> Expect.notEqual Leaks.baseUrl
|
|
|
|
)
|
2023-12-21 22:17:34 +00:00
|
|
|
, fuzz2 fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
"Transaction"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setTransaction value
|
|
|
|
|> Context.getTransaction
|
|
|
|
|> Expect.notEqual Leaks.transaction
|
|
|
|
)
|
2023-12-21 22:17:34 +00:00
|
|
|
, fuzz2 fuzzer
|
2024-05-27 14:39:50 +00:00
|
|
|
versionsFuzzer
|
2023-12-21 22:17:34 +00:00
|
|
|
"Versions"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setVersions value
|
|
|
|
|> Context.getVersions
|
|
|
|
|> Expect.notEqual Leaks.versions
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
2023-12-21 22:17:34 +00:00
|
|
|
|
2023-12-21 22:16:21 +00:00
|
|
|
apiContext : Test
|
|
|
|
apiContext =
|
|
|
|
describe "Verify writing info"
|
2023-12-21 22:17:34 +00:00
|
|
|
[ fuzz2 fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
"Access token"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setAccessToken value
|
|
|
|
|> Context.getAccessToken
|
|
|
|
|> Expect.equal value
|
|
|
|
)
|
2023-12-21 22:17:34 +00:00
|
|
|
, fuzz2 fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
"Base URL"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setBaseUrl value
|
|
|
|
|> Context.getBaseUrl
|
|
|
|
|> Expect.equal value
|
|
|
|
)
|
2023-12-21 22:17:34 +00:00
|
|
|
, fuzz2 fuzzer
|
|
|
|
Fuzz.string
|
|
|
|
"Transaction"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setTransaction value
|
|
|
|
|> Context.getTransaction
|
|
|
|
|> Expect.equal value
|
|
|
|
)
|
2023-12-21 22:17:34 +00:00
|
|
|
, fuzz2 fuzzer
|
2024-05-27 14:39:50 +00:00
|
|
|
versionsFuzzer
|
2023-12-21 22:17:34 +00:00
|
|
|
"Versions"
|
2023-12-21 22:16:21 +00:00
|
|
|
(\context value ->
|
|
|
|
context
|
|
|
|
|> Context.apiFormat
|
|
|
|
|> Context.setVersions value
|
|
|
|
|> Context.getVersions
|
|
|
|
|> Expect.equal value
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
2023-12-21 22:17:34 +00:00
|
|
|
|
2024-05-30 21:15:40 +00:00
|
|
|
|
|
|
|
-- json : Test
|
|
|
|
-- json =
|
|
|
|
-- describe "JSON encode + JSON decode"
|
|
|
|
-- [ fuzz fuzzer
|
|
|
|
-- "JSON recode"
|
|
|
|
-- (\context ->
|
|
|
|
-- context
|
|
|
|
-- |> Context.encode
|
|
|
|
-- |> D.decodeValue Context.decoder
|
|
|
|
-- |> Expect.equal (Ok ( context, [] ))
|
|
|
|
-- )
|
|
|
|
-- ]
|