2019-10-31 06:11:24 +03:00
|
|
|
module StaticHttpUnitTests exposing (all)
|
|
|
|
|
|
|
|
import Dict exposing (Dict)
|
|
|
|
import Expect
|
2020-04-17 07:31:21 +03:00
|
|
|
import Json.Decode.Exploration
|
|
|
|
import OptimizedDecoder as Decode
|
2020-04-18 06:10:25 +03:00
|
|
|
import Pages.Internal.ApplicationType as ApplicationType
|
2019-12-11 17:13:02 +03:00
|
|
|
import Pages.StaticHttp as StaticHttp
|
2020-01-03 23:18:18 +03:00
|
|
|
import Pages.StaticHttp.Request as Request
|
2019-10-31 06:11:24 +03:00
|
|
|
import Pages.StaticHttpRequest as StaticHttpRequest
|
2019-11-12 04:48:08 +03:00
|
|
|
import Secrets
|
2019-10-31 06:11:24 +03:00
|
|
|
import Test exposing (Test, describe, only, test)
|
|
|
|
|
|
|
|
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets url =
|
|
|
|
StaticHttp.get (Secrets.succeed url)
|
|
|
|
|
|
|
|
|
2020-01-03 23:18:18 +03:00
|
|
|
requestsDict requestMap =
|
|
|
|
requestMap
|
|
|
|
|> List.map
|
|
|
|
(\( request, response ) ->
|
|
|
|
( request |> Request.hash
|
2020-10-06 06:35:15 +03:00
|
|
|
, Just response
|
2020-01-03 23:18:18 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|> Dict.fromList
|
|
|
|
|
|
|
|
|
|
|
|
get : String -> Request.Request
|
|
|
|
get url =
|
|
|
|
{ method = "GET"
|
|
|
|
, url = url
|
|
|
|
, headers = []
|
2020-01-04 00:57:45 +03:00
|
|
|
, body = StaticHttp.emptyBody
|
2020-01-03 23:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-31 06:11:24 +03:00
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "Static Http Requests"
|
|
|
|
[ test "andThen" <|
|
|
|
|
\() ->
|
2019-11-13 05:22:36 +03:00
|
|
|
StaticHttp.get (Secrets.succeed "first") (Decode.succeed "NEXT")
|
2019-10-31 06:11:24 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "NEXT" (Decode.succeed ())
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
|> (\request ->
|
2020-04-18 06:10:25 +03:00
|
|
|
StaticHttpRequest.resolveUrls ApplicationType.Cli
|
|
|
|
request
|
2020-01-03 23:18:18 +03:00
|
|
|
(requestsDict
|
|
|
|
[ ( get "first", "null" )
|
|
|
|
, ( get "NEXT", "null" )
|
2019-10-31 06:11:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-12 04:48:08 +03:00
|
|
|
|> Tuple.mapSecond (List.map Secrets.maskedLookup)
|
2020-01-03 23:18:18 +03:00
|
|
|
|> Expect.equal ( True, [ getReq "first", getReq "NEXT" ] )
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
, test "andThen staring with done" <|
|
|
|
|
\() ->
|
|
|
|
StaticHttp.succeed ()
|
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\_ ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "NEXT" (Decode.succeed ())
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
|> (\request ->
|
2020-04-18 06:10:25 +03:00
|
|
|
StaticHttpRequest.resolveUrls ApplicationType.Cli
|
|
|
|
request
|
2020-01-03 23:18:18 +03:00
|
|
|
(requestsDict
|
|
|
|
[ ( get "NEXT", "null" )
|
2019-10-31 06:11:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-12 04:48:08 +03:00
|
|
|
|> Tuple.mapSecond (List.map Secrets.maskedLookup)
|
2020-01-03 23:18:18 +03:00
|
|
|
|> Expect.equal ( True, [ getReq "NEXT" ] )
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
, test "map" <|
|
|
|
|
\() ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "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 ())
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "NEXT" (Decode.succeed ())
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
|> StaticHttp.map (\_ -> ())
|
|
|
|
|> (\request ->
|
2020-04-18 06:10:25 +03:00
|
|
|
StaticHttpRequest.resolveUrls ApplicationType.Cli
|
|
|
|
request
|
2020-01-03 23:18:18 +03:00
|
|
|
(requestsDict
|
|
|
|
[ ( get "first", "null" )
|
|
|
|
, ( get "NEXT", "null" )
|
2019-10-31 06:11:24 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-12 04:48:08 +03:00
|
|
|
|> Tuple.mapSecond (List.map Secrets.maskedLookup)
|
2020-01-03 23:18:18 +03:00
|
|
|
|> Expect.equal ( True, [ getReq "first", getReq "NEXT" ] )
|
2019-11-01 23:29:09 +03:00
|
|
|
)
|
|
|
|
, test "andThen chain with 1 response available and 1 pending" <|
|
|
|
|
\() ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "first" (Decode.succeed "NEXT")
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "NEXT" (Decode.succeed ())
|
2019-11-01 23:29:09 +03:00
|
|
|
)
|
|
|
|
|> (\request ->
|
2020-04-18 06:10:25 +03:00
|
|
|
StaticHttpRequest.resolveUrls ApplicationType.Cli
|
|
|
|
request
|
2020-01-03 23:18:18 +03:00
|
|
|
(requestsDict
|
|
|
|
[ ( get "first", "null" )
|
2019-11-01 23:29:09 +03:00
|
|
|
]
|
|
|
|
)
|
2019-11-12 04:48:08 +03:00
|
|
|
|> Tuple.mapSecond (List.map Secrets.maskedLookup)
|
2020-01-03 23:18:18 +03:00
|
|
|
|> Expect.equal ( False, [ getReq "first", getReq "NEXT" ] )
|
2019-11-01 23:29:09 +03:00
|
|
|
)
|
|
|
|
, test "andThen chain with 1 response available and 2 pending" <|
|
|
|
|
\() ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "first" Decode.int
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\continueUrl ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "NEXT" Decode.string
|
2019-11-01 23:29:09 +03:00
|
|
|
|> StaticHttp.andThen
|
|
|
|
(\_ ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "LAST"
|
2019-11-01 23:29:09 +03:00
|
|
|
Decode.string
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|> (\request ->
|
2020-04-18 06:10:25 +03:00
|
|
|
StaticHttpRequest.resolveUrls ApplicationType.Cli
|
|
|
|
request
|
2020-01-03 23:18:18 +03:00
|
|
|
(requestsDict
|
|
|
|
[ ( get "first", "1" )
|
|
|
|
]
|
|
|
|
)
|
2019-11-12 04:48:08 +03:00
|
|
|
|> Tuple.mapSecond (List.map Secrets.maskedLookup)
|
2020-01-03 23:18:18 +03:00
|
|
|
|> Expect.equal ( False, [ getReq "first", getReq "NEXT" ] )
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
]
|
2019-11-11 23:40:38 +03:00
|
|
|
|
|
|
|
|
2020-01-04 00:37:50 +03:00
|
|
|
getReq : String -> StaticHttp.RequestDetails
|
2020-01-03 23:18:18 +03:00
|
|
|
getReq url =
|
2020-01-04 00:22:53 +03:00
|
|
|
{ url = url
|
|
|
|
, method = "GET"
|
|
|
|
, headers = []
|
2020-01-04 00:57:45 +03:00
|
|
|
, body = StaticHttp.emptyBody
|
2020-01-04 00:22:53 +03:00
|
|
|
}
|