2019-10-31 06:11:24 +03:00
|
|
|
module StaticHttpUnitTests exposing (all)
|
|
|
|
|
2021-04-20 17:31:19 +03:00
|
|
|
import DataSource
|
2021-04-20 23:52:54 +03:00
|
|
|
import DataSource.Http
|
2020-12-07 19:41:10 +03:00
|
|
|
import Dict
|
2019-10-31 06:11:24 +03:00
|
|
|
import Expect
|
2020-04-17 07:31:21 +03:00
|
|
|
import OptimizedDecoder as Decode
|
2020-04-18 06:10:25 +03:00
|
|
|
import Pages.Internal.ApplicationType as ApplicationType
|
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
|
2020-12-07 19:41:10 +03:00
|
|
|
import Test exposing (Test, describe, test)
|
2019-10-31 06:11:24 +03:00
|
|
|
|
|
|
|
|
2021-06-04 03:59:58 +03:00
|
|
|
getWithoutSecrets : String -> Decode.Decoder a -> DataSource.DataSource a
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets url =
|
2021-04-20 23:52:54 +03:00
|
|
|
DataSource.Http.get (Secrets.succeed url)
|
2019-11-13 05:22:36 +03:00
|
|
|
|
|
|
|
|
2021-06-04 03:59:58 +03:00
|
|
|
requestsDict : List ( Request.Request, b ) -> Dict.Dict String (Maybe b)
|
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 = []
|
2021-07-30 01:57:44 +03:00
|
|
|
, body = DataSource.Http.emptyBody
|
2020-01-03 23:18:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-31 06:11:24 +03:00
|
|
|
all : Test
|
|
|
|
all =
|
2021-04-01 05:55:28 +03:00
|
|
|
describe "Static Http Requests unit tests"
|
2019-10-31 06:11:24 +03:00
|
|
|
[ test "andThen" <|
|
|
|
|
\() ->
|
2021-04-20 23:52:54 +03:00
|
|
|
DataSource.Http.get (Secrets.succeed "first") (Decode.succeed "NEXT")
|
2021-04-20 17:31:19 +03:00
|
|
|
|> DataSource.andThen
|
2021-04-03 00:44:40 +03:00
|
|
|
(\_ ->
|
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
|
|
|
]
|
|
|
|
)
|
2021-06-03 21:00:48 +03:00
|
|
|
|> List.map Secrets.maskedLookup
|
|
|
|
|> Expect.equal [ getReq "first", getReq "NEXT" ]
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
, test "andThen staring with done" <|
|
|
|
|
\() ->
|
2021-04-20 17:31:19 +03:00
|
|
|
DataSource.succeed ()
|
|
|
|
|> DataSource.andThen
|
2019-10-31 06:11:24 +03:00
|
|
|
(\_ ->
|
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
|
|
|
]
|
|
|
|
)
|
2021-06-03 21:00:48 +03:00
|
|
|
|> List.map Secrets.maskedLookup
|
|
|
|
|> Expect.equal [ 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")
|
2021-04-20 17:31:19 +03:00
|
|
|
|> DataSource.andThen
|
2021-04-03 00:44:40 +03:00
|
|
|
(\_ ->
|
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
|
|
|
)
|
2021-04-20 17:31:19 +03:00
|
|
|
|> DataSource.map (\_ -> ())
|
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
|
|
|
]
|
|
|
|
)
|
2021-06-03 21:00:48 +03:00
|
|
|
|> List.map Secrets.maskedLookup
|
|
|
|
|> Expect.equal [ 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")
|
2021-04-20 17:31:19 +03:00
|
|
|
|> DataSource.andThen
|
2021-04-03 00:44:40 +03:00
|
|
|
(\_ ->
|
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
|
|
|
]
|
|
|
|
)
|
2021-06-03 21:00:48 +03:00
|
|
|
|> List.map Secrets.maskedLookup
|
|
|
|
|> Expect.equal [ 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
|
2021-04-20 17:31:19 +03:00
|
|
|
|> DataSource.andThen
|
2021-04-03 00:44:40 +03:00
|
|
|
(\_ ->
|
2019-11-13 05:22:36 +03:00
|
|
|
getWithoutSecrets "NEXT" Decode.string
|
2021-04-20 17:31:19 +03:00
|
|
|
|> DataSource.andThen
|
2019-11-01 23:29:09 +03:00
|
|
|
(\_ ->
|
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" )
|
|
|
|
]
|
|
|
|
)
|
2021-06-03 21:00:48 +03:00
|
|
|
|> List.map Secrets.maskedLookup
|
|
|
|
|> Expect.equal [ getReq "first", getReq "NEXT" ]
|
2019-10-31 06:11:24 +03:00
|
|
|
)
|
|
|
|
]
|
2019-11-11 23:40:38 +03:00
|
|
|
|
|
|
|
|
2021-04-20 23:52:54 +03:00
|
|
|
getReq : String -> DataSource.Http.RequestDetails
|
2020-01-03 23:18:18 +03:00
|
|
|
getReq url =
|
2020-01-04 00:22:53 +03:00
|
|
|
{ url = url
|
|
|
|
, method = "GET"
|
|
|
|
, headers = []
|
2021-07-30 01:57:44 +03:00
|
|
|
, body = DataSource.Http.emptyBody
|
2020-01-04 00:22:53 +03:00
|
|
|
}
|