2019-10-31 06:11:24 +03:00
|
|
|
module StaticHttpUnitTests exposing (all)
|
|
|
|
|
|
|
|
import Dict exposing (Dict)
|
|
|
|
import Expect
|
|
|
|
import Json.Decode as Decode
|
|
|
|
import Pages.Internal.Secrets
|
|
|
|
import Pages.StaticHttpRequest as StaticHttpRequest
|
|
|
|
import StaticHttp
|
|
|
|
import Test exposing (Test, describe, only, test)
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "Static Http Requests"
|
|
|
|
[ test "andThen" <|
|
|
|
|
\() ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "first" (Decode.succeed "NEXT")
|
2019-10-31 06:11:24 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-05 18:53:17 +03:00
|
|
|
-- StaticHttp.get continueUrl (Decode.succeed ())
|
|
|
|
StaticHttp.get "NEXT" (Decode.succeed ())
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
|> (\request ->
|
|
|
|
StaticHttpRequest.resolveUrls request
|
|
|
|
(Dict.fromList
|
2019-11-08 08:47:36 +03:00
|
|
|
[ ( "[GET]first", "null" )
|
|
|
|
, ( "[GET]NEXT", "null" )
|
2019-10-31 06:11:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-01 23:29:09 +03:00
|
|
|
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|
|
|
|
|> Expect.equal ( True, [ "first", "NEXT" ] )
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
, test "andThen staring with done" <|
|
|
|
|
\() ->
|
|
|
|
StaticHttp.succeed ()
|
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\_ ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "NEXT" (Decode.succeed ())
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
|> (\request ->
|
|
|
|
StaticHttpRequest.resolveUrls request
|
|
|
|
(Dict.fromList
|
2019-11-08 08:47:36 +03:00
|
|
|
[ ( "[GET]NEXT", "null" )
|
2019-10-31 06:11:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-01 23:29:09 +03:00
|
|
|
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|
|
|
|
|> Expect.equal ( True, [ "NEXT" ] )
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
, test "map" <|
|
|
|
|
\() ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "first" (Decode.succeed "NEXT")
|
2019-10-31 06:11:24 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-05 18:53:17 +03:00
|
|
|
-- StaticHttp.get continueUrl (Decode.succeed ())
|
|
|
|
StaticHttp.get "NEXT" (Decode.succeed ())
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
|> StaticHttp.map (\_ -> ())
|
|
|
|
|> (\request ->
|
|
|
|
StaticHttpRequest.resolveUrls request
|
|
|
|
(Dict.fromList
|
2019-11-08 08:47:36 +03:00
|
|
|
[ ( "[GET]first", "null" )
|
|
|
|
, ( "[GET]NEXT", "null" )
|
2019-10-31 06:11:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-01 23:29:09 +03:00
|
|
|
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|
|
|
|
|> Expect.equal ( True, [ "first", "NEXT" ] )
|
|
|
|
)
|
|
|
|
, test "andThen chain with 1 response available and 1 pending" <|
|
|
|
|
\() ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "first" (Decode.succeed "NEXT")
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "NEXT" (Decode.succeed ())
|
2019-11-01 23:29:09 +03:00
|
|
|
)
|
|
|
|
|> (\request ->
|
|
|
|
StaticHttpRequest.resolveUrls request
|
|
|
|
(Dict.fromList
|
2019-11-08 08:47:36 +03:00
|
|
|
[ ( "[GET]first", "null" )
|
2019-11-01 23:29:09 +03:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|
2019-11-02 17:43:25 +03:00
|
|
|
|> Expect.equal ( False, [ "first", "NEXT" ] )
|
2019-11-01 23:29:09 +03:00
|
|
|
)
|
|
|
|
, test "andThen chain with 1 response available and 2 pending" <|
|
|
|
|
\() ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "first" Decode.int
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "NEXT" Decode.string
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\_ ->
|
2019-11-05 18:53:17 +03:00
|
|
|
StaticHttp.get "LAST"
|
2019-11-01 23:29:09 +03:00
|
|
|
Decode.string
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|> (\request ->
|
|
|
|
StaticHttpRequest.resolveUrls request
|
2019-11-08 08:47:36 +03:00
|
|
|
(Dict.fromList [ ( "[GET]first", "1" ) ])
|
2019-11-01 23:29:09 +03:00
|
|
|
|> Tuple.mapSecond (List.map Pages.Internal.Secrets.useFakeSecrets)
|
|
|
|
|> Expect.equal ( False, [ "first", "NEXT" ] )
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
]
|