-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_integration_test.go
44 lines (34 loc) · 1.12 KB
/
server_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package poker_test
import (
poker "learn-go-with-tests"
"net/http"
"net/http/httptest"
"testing"
)
func TestRecordingWinsAndRetrievingThem(t *testing.T) {
database, closeDatabase := createTempFile(t, `[]`)
defer closeDatabase()
store, err := poker.NewFileSystemPlayerStore(database)
assertNoError(t, err)
server := mustMakePlayerServer(t, store, dummyGameSpy)
player := "Pepper"
server.ServeHTTP(httptest.NewRecorder(), newPostWinRequest(player))
server.ServeHTTP(httptest.NewRecorder(), newPostWinRequest(player))
server.ServeHTTP(httptest.NewRecorder(), newPostWinRequest(player))
t.Run("get score", func(t *testing.T) {
response := httptest.NewRecorder()
server.ServeHTTP(response, newGetScoreRequest(player))
assertStatus(t, response, http.StatusOK)
assertResponseBody(t, response.Body.String(), "3")
})
t.Run("get league", func(t *testing.T) {
response := httptest.NewRecorder()
server.ServeHTTP(response, newLeagueRequest())
assertStatus(t, response, http.StatusOK)
got := getLeagueFromResponse(t, response.Body)
want := []poker.Player{
{"Pepper", 3},
}
assertLeague(t, got, want)
})
}