diff --git a/src/Pages/Internal/Platform/ToJsPayload.elm b/src/Pages/Internal/Platform/ToJsPayload.elm index 5fc0e489..6c96faf4 100644 --- a/src/Pages/Internal/Platform/ToJsPayload.elm +++ b/src/Pages/Internal/Platform/ToJsPayload.elm @@ -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 diff --git a/tests/StaticHttpRequestsTests.elm b/tests/StaticHttpRequestsTests.elm index cf83688f..0b1c1e7b 100644 --- a/tests/StaticHttpRequestsTests.elm +++ b/tests/StaticHttpRequestsTests.elm @@ -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