This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
persistScoreTests : Test | |
persistScoreTests = | |
describe "when a score is persisted" | |
[ describe "when the request is successful" <| | |
let | |
state = | |
Headless.givenCommand (\_ -> HttpPersistScore.executeWith "http://fake-server/scores" ScoreTagger 87) | |
|> Spy.use [ Http.serve [ storeScoreStub 87, scoreRequestStub [ 81, 87, 98, 123 ] ] ] | |
in | |
[ test "it POSTs the new score to the score service" <| | |
\() -> | |
state | |
|> Http.expectThat (post "http://fake-server/scores") ( | |
exactly 1 <| hasBody "{\"score\":87}" | |
) | |
, test "it GETs the scores" <| | |
\() -> | |
state | |
|> Http.expect (get "http://fake-server/scores") | |
, test "it returns the scores" <| | |
\() -> | |
state | |
|> Headless.expectMessages (exactly 1 <| | |
Expect.equal (ScoreTagger [ 81, 87, 98, 123 ]) | |
) | |
] | |
type TestMsg | |
= ScoreTagger (List Score) | |
storeScoreStub : Score -> HttpResponseStub | |
storeScoreStub score = | |
Stub.for (post "http://fake-server/scores") | |
|> withBody ("{\"score\":" ++ toString score ++ "}") | |
scoreRequestStub : List Score -> HttpResponseStub | |
scoreRequestStub scores = | |
Stub.for (get "http://fake-server/scores") | |
|> withBody (bodyForScores scores) | |
bodyForScores : List Score -> String | |
bodyForScores scores = | |
"[" | |
++ String.join "," | |
(List.map (\s -> "{\"score\":" ++ toString s ++ "}") scores) | |
++ "]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment