-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_intergration_test.go
41 lines (32 loc) · 1.12 KB
/
server_intergration_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
package poker_test
import (
"net/http"
"net/http/httptest"
"testing"
poker "github.com/ljones140/golang-player-webserver"
)
func TestRecordingWinsAndRetrievingThem(t *testing.T) {
database, cleanDatabase := createTempFile(t, `[]`)
defer cleanDatabase()
store, _ := poker.NewFileSystemPlayerStore(database)
server := mustMakePlayerServer(t, store, dummyGame)
player := "Pepper"
server.ServeHTTP(httptest.NewRecorder(), poker.NewPostWinRequest(player))
server.ServeHTTP(httptest.NewRecorder(), poker.NewPostWinRequest(player))
server.ServeHTTP(httptest.NewRecorder(), poker.NewPostWinRequest(player))
t.Run("get score", func(t *testing.T) {
response := httptest.NewRecorder()
server.ServeHTTP(response, poker.NewGetScoreRequest(player))
assertStatus(t, response, http.StatusOK)
poker.AssertResponseBody(t, response.Body.String(), "3")
})
t.Run("get league", func(t *testing.T) {
response := httptest.NewRecorder()
server.ServeHTTP(response, poker.NewGetLeagueRequest())
got := poker.GetLeagueFromResponse(t, response.Body)
want := []poker.Player{
{"Pepper", 3},
}
poker.AssertLeague(t, got, want)
})
}