mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 04:43:03 +03:00
Add test case for generating files with static http data.
This commit is contained in:
parent
229a8c4445
commit
0d39eafb06
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user