forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reports_test.go
137 lines (121 loc) · 5.78 KB
/
reports_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
package main
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestRankingsCsvReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
ranking1 := Ranking{1114, 2, 18, 1100, 625, 90, 554, 0.254, 9, 1, 0, 0, 10}
ranking2 := Ranking{254, 1, 20, 1100, 625, 90, 554, 0.254, 10, 0, 0, 0, 10}
db.CreateRanking(&ranking1)
db.CreateRanking(&ranking2)
recorder := getHttpResponse("/reports/csv/rankings")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/plain", recorder.HeaderMap["Content-Type"][0])
expectedBody := "Rank,TeamId,QualificationScore,AssistPoints,AutoPoints,TrussCatchPoints,GoalFoulPoints," +
"Wins,Losses,Ties,Disqualifications,Played\n1,254,20,1100,625,90,554,10,0,0,0,10\n2,1114,18,1100,625," +
"90,554,9,1,0,0,10\n\n"
assert.Equal(t, expectedBody, recorder.Body.String())
}
func TestRankingsPdfReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
eventSettings, _ = db.GetEventSettings()
ranking1 := Ranking{1114, 2, 18, 1100, 625, 90, 554, 0.254, 9, 1, 0, 0, 10}
ranking2 := Ranking{254, 1, 20, 1100, 625, 90, 554, 0.254, 10, 0, 0, 0, 10}
db.CreateRanking(&ranking1)
db.CreateRanking(&ranking2)
// Can't really parse the PDF content and check it, so just check that what's sent back is a PDF.
recorder := getHttpResponse("/reports/pdf/rankings")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "application/pdf", recorder.HeaderMap["Content-Type"][0])
}
func TestScheduleCsvReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
match1 := Match{Type: "qualification", DisplayName: "1", Time: time.Unix(0, 0), Red1: 1, Red2: 2, Red3: 3,
Blue1: 4, Blue2: 5, Blue3: 6, Blue1IsSurrogate: true, Blue2IsSurrogate: true, Blue3IsSurrogate: true}
match2 := Match{Type: "qualification", DisplayName: "2", Time: time.Unix(600, 0), Red1: 7, Red2: 8, Red3: 9,
Blue1: 10, Blue2: 11, Blue3: 12, Red1IsSurrogate: true, Red2IsSurrogate: true, Red3IsSurrogate: true}
match3 := Match{Type: "practice", DisplayName: "1", Time: time.Now(), Red1: 6, Red2: 5, Red3: 4,
Blue1: 3, Blue2: 2, Blue3: 1}
db.CreateMatch(&match1)
db.CreateMatch(&match2)
db.CreateMatch(&match3)
recorder := getHttpResponse("/reports/csv/schedule/qualification")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/plain", recorder.HeaderMap["Content-Type"][0])
expectedBody := "Match,Type,Time,Red1,Red1IsSurrogate,Red2,Red2IsSurrogate,Red3,Red3IsSurrogate,Blue1," +
"Blue1IsSurrogate,Blue2,Blue2IsSurrogate,Blue3,Blue3IsSurrogate\n1,qualification," +
"1969-12-31 16:00:00 -0800 PST,1,false,2,false,3,false,4,true,5,true,6,true\n" +
"2,qualification,1969-12-31 16:10:00 -0800 PST,7,true,8,true,9,true,10,false,11,false,12,false\n\n"
assert.Equal(t, expectedBody, recorder.Body.String())
}
func TestSchedulePdfReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
eventSettings, _ = db.GetEventSettings()
match := Match{Type: "practice", DisplayName: "1", Time: time.Unix(0, 0), Red1: 1, Red2: 2, Red3: 3,
Blue1: 4, Blue2: 5, Blue3: 6, Blue1IsSurrogate: true, Blue2IsSurrogate: true, Blue3IsSurrogate: true}
db.CreateMatch(&match)
team := Team{Id: 254, Name: "NASA", Nickname: "The Cheesy Poofs", City: "San Jose", StateProv: "CA",
Country: "USA", RookieYear: 1999, RobotName: "Barrage"}
db.CreateTeam(&team)
// Can't really parse the PDF content and check it, so just check that what's sent back is a PDF.
recorder := getHttpResponse("/reports/pdf/schedule/practice")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "application/pdf", recorder.HeaderMap["Content-Type"][0])
}
func TestTeamsCsvReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
team1 := Team{Id: 254, Name: "NASA", Nickname: "The Cheesy Poofs", City: "San Jose", StateProv: "CA",
Country: "USA", RookieYear: 1999, RobotName: "Barrage"}
team2 := Team{Id: 1114, Name: "GM", Nickname: "Simbotics", City: "St. Catharines", StateProv: "ON",
Country: "Canada", RookieYear: 2003, RobotName: "Simbot Evolution"}
db.CreateTeam(&team1)
db.CreateTeam(&team2)
recorder := getHttpResponse("/reports/csv/teams")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/plain", recorder.HeaderMap["Content-Type"][0])
expectedBody := "Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName\n254,\"NASA\"," +
"\"The Cheesy Poofs\",\"San Jose\",\"CA\",\"USA\",1999,\"Barrage\"\n1114,\"GM\",\"Simbotics\"," +
"\"St. Catharines\",\"ON\",\"Canada\",2003,\"Simbot Evolution\"\n\n"
assert.Equal(t, expectedBody, recorder.Body.String())
}
func TestTeamsPdfReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
eventSettings, _ = db.GetEventSettings()
team := Team{Id: 254, Name: "NASA", Nickname: "The Cheesy Poofs", City: "San Jose", StateProv: "CA",
Country: "USA", RookieYear: 1999, RobotName: "Barrage"}
db.CreateTeam(&team)
// Can't really parse the PDF content and check it, so just check that what's sent back is a PDF.
recorder := getHttpResponse("/reports/pdf/teams")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "application/pdf", recorder.HeaderMap["Content-Type"][0])
}
func TestWpaKeysCsvReport(t *testing.T) {
clearDb()
defer clearDb()
db, _ = OpenDatabase(testDbPath)
team1 := Team{Id: 254, WpaKey: "12345678"}
team2 := Team{Id: 1114, WpaKey: "9876543210"}
db.CreateTeam(&team1)
db.CreateTeam(&team2)
recorder := getHttpResponse("/reports/csv/wpa_keys")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/csv", recorder.HeaderMap["Content-Type"][0])
assert.Equal(t, "attachment; filename=wpa_keys.csv", recorder.HeaderMap["Content-Disposition"][0])
assert.Equal(t, "254,12345678\r\n1114,9876543210\r\n", recorder.Body.String())
}