Add test case for generating files with static http data.

This commit is contained in:
Dillon Kearns 2020-06-13 13:43:35 -07:00
parent 229a8c4445
commit 0d39eafb06
2 changed files with 59 additions and 1 deletions

View File

@ -115,7 +115,12 @@ successCodec =
]
)
)
(Decode.succeed [])
(Decode.list
(Decode.map2 (\path content -> { path = path, content = content })
(Decode.string |> Decode.map (String.split "/") |> Decode.field "path")
(Decode.string |> Decode.field "content")
)
)
)
|> Codec.field "staticHttpCache"
.staticHttpCache

View File

@ -675,6 +675,39 @@ I ran into a problem when parsing the metadata for the page with this path:
Found an unhandled HTML tag in markdown doc."""
]
]
, describe "generateFiles"
[ test "initial requests are sent out" <|
\() ->
startLowLevel
(StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
(starDecoder
|> Decode.map
(\starCount ->
[ Ok
{ path = [ "test.txt" ]
, content = "Star count: " ++ String.fromInt starCount
}
]
)
)
)
(Ok ())
[]
[]
|> ProgramTest.simulateHttpOk
"GET"
"https://api.github.com/repos/dillonkearns/elm-pages"
"""{ "stargazer_count": 86 }"""
|> expectSuccessNew
[ \success ->
success.filesToGenerate
|> Expect.equal
[ { path = [ "test.txt" ]
, content = "Star count: 86"
}
]
]
]
]
@ -976,6 +1009,26 @@ expectSuccess expectedRequests previous =
)
expectSuccessNew : List (ToJsPayload.ToJsSuccessPayload PathKey -> Expect.Expectation) -> ProgramTest model msg effect -> Expect.Expectation
expectSuccessNew expectations previous =
previous
|> ProgramTest.expectOutgoingPortValues
"toJsPort"
(Codec.decoder ToJsPayload.toJsCodec)
(\value ->
case value of
[ ToJsPayload.Success portPayload ] ->
portPayload
|> Expect.all expectations
[ _ ] ->
Expect.fail "Expected success port."
_ ->
Expect.fail ("Expected ports to be called once, but instead there were " ++ String.fromInt (List.length value) ++ " calls.")
)
expectError : List String -> ProgramTest model msg effect -> Expect.Expectation
expectError expectedErrors previous =
previous