mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Fixed broken tests.
This commit is contained in:
@@ -434,6 +434,7 @@ func TestSubstituteTeam(t *testing.T) {
|
||||
db, err = OpenDatabase(testDbPath)
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
db.CreateTeam(&Team{Id: 101})
|
||||
db.CreateTeam(&Team{Id: 102})
|
||||
@@ -469,19 +470,16 @@ func TestSubstituteTeam(t *testing.T) {
|
||||
match2, _ := db.GetMatchById(match.Id)
|
||||
assert.Equal(t, 107, match2.Red1)
|
||||
|
||||
// Check that substitution is disallowed in qualification and elimination matches.
|
||||
// Check that substitution is disallowed in qualification matches.
|
||||
match = Match{Type: "qualification", Red1: 101, Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
db.CreateMatch(&match)
|
||||
mainArena.LoadMatch(&match)
|
||||
err = mainArena.SubstituteTeam(107, "R1")
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Contains(t, err.Error(), "Can only substitute teams for test and practice matches")
|
||||
assert.Contains(t, err.Error(), "Can't substitute teams for qualification matches.")
|
||||
}
|
||||
match = Match{Type: "elimination", Red1: 101, Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
db.CreateMatch(&match)
|
||||
mainArena.LoadMatch(&match)
|
||||
err = mainArena.SubstituteTeam(107, "R1")
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Contains(t, err.Error(), "Can only substitute teams for test and practice matches")
|
||||
}
|
||||
assert.Nil(t, mainArena.SubstituteTeam(107, "R1"))
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ func TestAudienceDisplayWebsocket(t *testing.T) {
|
||||
db, err = OpenDatabase(testDbPath)
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
server, wsUrl := startTestServer()
|
||||
@@ -48,6 +49,7 @@ func TestAudienceDisplayWebsocket(t *testing.T) {
|
||||
readWebsocketType(t, ws, "setMatch")
|
||||
readWebsocketType(t, ws, "realtimeScore")
|
||||
readWebsocketType(t, ws, "setFinalScore")
|
||||
readWebsocketType(t, ws, "allianceSelection")
|
||||
|
||||
// Run through a match cycle.
|
||||
mainArena.matchLoadTeamsNotifier.Notify(nil)
|
||||
@@ -181,6 +183,7 @@ func TestScoringDisplayWebsocket(t *testing.T) {
|
||||
db, err = OpenDatabase(testDbPath)
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
server, wsUrl := startTestServer()
|
||||
@@ -235,8 +238,9 @@ func TestScoringDisplayWebsocket(t *testing.T) {
|
||||
blueWs.Write("undo", nil)
|
||||
blueWs.Write("scoredLow", nil)
|
||||
blueWs.Write("commit", nil)
|
||||
mainArena.MatchState = POST_MATCH
|
||||
redWs.Write("commitMatch", nil)
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := 0; i < 11; i++ {
|
||||
readWebsocketType(t, redWs, "score")
|
||||
}
|
||||
for i := 0; i < 24; i++ {
|
||||
@@ -288,11 +292,12 @@ func TestScoringDisplayWebsocket(t *testing.T) {
|
||||
assert.False(t, mainArena.blueRealtimeScore.TeleopCommitted)
|
||||
|
||||
// Load another match to reset the results.
|
||||
mainArena.ResetMatch()
|
||||
mainArena.LoadTestMatch()
|
||||
readWebsocketType(t, redWs, "score")
|
||||
readWebsocketType(t, blueWs, "score")
|
||||
assert.Equal(t, RealtimeScore{}, *mainArena.redRealtimeScore)
|
||||
assert.Equal(t, RealtimeScore{}, *mainArena.blueRealtimeScore)
|
||||
assert.Equal(t, *NewRealtimeScore(), *mainArena.redRealtimeScore)
|
||||
assert.Equal(t, *NewRealtimeScore(), *mainArena.blueRealtimeScore)
|
||||
}
|
||||
|
||||
func TestRefereeDisplay(t *testing.T) {
|
||||
@@ -317,6 +322,7 @@ func TestRefereeDisplayWebsocket(t *testing.T) {
|
||||
db, err = OpenDatabase(testDbPath)
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
server, wsUrl := startTestServer()
|
||||
@@ -378,6 +384,7 @@ func TestRefereeDisplayWebsocket(t *testing.T) {
|
||||
assert.Equal(t, 1, len(mainArena.redRealtimeScore.Fouls))
|
||||
|
||||
// Test match committing.
|
||||
mainArena.MatchState = POST_MATCH
|
||||
ws.Write("commitMatch", foulData)
|
||||
readWebsocketType(t, ws, "reload")
|
||||
assert.True(t, mainArena.redRealtimeScore.FoulsCommitted)
|
||||
|
||||
@@ -18,7 +18,8 @@ func TestEventSettingsReadWrite(t *testing.T) {
|
||||
eventSettings, err := db.GetEventSettings()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, EventSettings{Id: 0, Name: "Untitled Event", Code: "UE", DisplayBackgroundColor: "#00ff00",
|
||||
NumElimAlliances: 8, SelectionRound2Order: "L", SelectionRound3Order: ""}, *eventSettings)
|
||||
NumElimAlliances: 8, SelectionRound2Order: "L", SelectionRound3Order: "",
|
||||
TeamInfoDownloadEnabled: true}, *eventSettings)
|
||||
|
||||
eventSettings.Name = "Chezy Champs"
|
||||
eventSettings.Code = "cc"
|
||||
|
||||
@@ -208,6 +208,7 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
db.CreateTeam(&Team{Id: 254})
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
server, wsUrl := startTestServer()
|
||||
@@ -223,6 +224,7 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
readWebsocketType(t, ws, "matchTime")
|
||||
readWebsocketType(t, ws, "setAudienceDisplay")
|
||||
readWebsocketType(t, ws, "scoringStatus")
|
||||
readWebsocketType(t, ws, "setAllianceStationDisplay")
|
||||
|
||||
// Test that a server-side error is communicated to the client.
|
||||
ws.Write("nonexistenttype", nil)
|
||||
@@ -297,6 +299,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
db.CreateTeam(&Team{Id: 254})
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
server, wsUrl := startTestServer()
|
||||
@@ -321,13 +324,15 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
mainArena.AllianceStations["B3"].Bypass = true
|
||||
mainArena.StartMatch()
|
||||
mainArena.Update()
|
||||
messages := readWebsocketMultiple(t, ws, 3)
|
||||
messages := readWebsocketMultiple(t, ws, 4)
|
||||
statusReceived, matchTime := getStatusMatchTime(t, messages)
|
||||
assert.Equal(t, true, statusReceived)
|
||||
assert.Equal(t, 2, matchTime.MatchState)
|
||||
assert.Equal(t, 0, matchTime.MatchTimeSec)
|
||||
_, ok := messages["setAudienceDisplay"]
|
||||
assert.True(t, ok)
|
||||
_, ok = messages["setAllianceStationDisplay"]
|
||||
assert.True(t, ok)
|
||||
mainArena.scoringStatusNotifier.Notify(nil)
|
||||
readWebsocketType(t, ws, "scoringStatus")
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
eventSettings, _ = db.GetEventSettings()
|
||||
mainArena.Setup()
|
||||
|
||||
match := Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 101,
|
||||
Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
@@ -73,7 +74,7 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
// Update the score to something else.
|
||||
postBody := "redScoreJson={\"AutoMobilityBonuses\":3}&blueScoreJson={\"Cycles\":[{\"ScoredHigh\":true}]}&" +
|
||||
"redFoulsJson=[{\"TeamId\":103,\"IsTechnical\":false}]&blueFoulsJson=[{\"TeamId\":104,\"IsTechnical\":" +
|
||||
"true}]&cardsJson={\"RedCardTeamIds\":[105]}"
|
||||
"true}]&redCardsJson={\"105\":\"yellow\"}&blueCardsJson={}"
|
||||
recorder = postHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id), postBody)
|
||||
assert.Equal(t, 302, recorder.Code)
|
||||
|
||||
@@ -111,7 +112,7 @@ func TestMatchReviewCreateNewResult(t *testing.T) {
|
||||
|
||||
// Update the score to something else.
|
||||
postBody := "redScoreJson={\"AutoHighHot\":4}&blueScoreJson={\"Cycles\":[{\"Assists\":3," +
|
||||
"\"ScoredLow\":true}]}&redFoulsJson=[]&blueFoulsJson=[]&cardsJson={}"
|
||||
"\"ScoredLow\":true}]}&redFoulsJson=[]&blueFoulsJson=[]&redCardsJson={}&blueCardsJson={}"
|
||||
recorder = postHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id), postBody)
|
||||
assert.Equal(t, 302, recorder.Code)
|
||||
|
||||
|
||||
34
tba_test.go
34
tba_test.go
@@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -28,9 +29,11 @@ func TestPublishTeams(t *testing.T) {
|
||||
// Mock the TBA server.
|
||||
tbaServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Contains(t, r.URL.String(), "event/my_event_code")
|
||||
assert.Equal(t, "my_secret_id", r.PostFormValue("secret-id"))
|
||||
assert.Equal(t, "my_secret", r.PostFormValue("secret"))
|
||||
assert.Equal(t, "[\"frc254\",\"frc1114\"]", r.PostFormValue("team_list"))
|
||||
var reader bytes.Buffer
|
||||
reader.ReadFrom(r.Body)
|
||||
assert.Equal(t, "[\"frc254\",\"frc1114\"]", reader.String())
|
||||
assert.Equal(t, "my_secret_id", r.Header["X-Tba-Auth-Id"][0])
|
||||
assert.Equal(t, "f5c022fde6d1186ea0719fe28ab6cc63", r.Header["X-Tba-Auth-Sig"][0])
|
||||
}))
|
||||
defer tbaServer.Close()
|
||||
tbaBaseUrl = tbaServer.URL
|
||||
@@ -56,12 +59,17 @@ func TestPublishMatches(t *testing.T) {
|
||||
|
||||
// Mock the TBA server.
|
||||
tbaServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "[{\"comp_level\":\"qm\",\"set_number\":0,\"match_number\":2,\"alliances\":{\"blue\":"+
|
||||
"{\"score\":593,\"teams\":[\"frc10\",\"frc11\",\"frc12\"]},\"red\":{\"score\":312,\"teams\":[\"frc7\""+
|
||||
",\"frc8\",\"frc9\"]}},\"time_string\":\"4:10 PM\"},{\"comp_level\":\"sf\",\"set_number\":2,"+
|
||||
"\"match_number\":2,\"alliances\":{\"blue\":{\"score\":null,\"teams\":[\"frc0\",\"frc0\",\"frc0\"]},"+
|
||||
"\"red\":{\"score\":null,\"teams\":[\"frc0\",\"frc0\",\"frc0\"]}},\"time_string\":\"5:00 PM\"}]",
|
||||
r.PostFormValue("matches"))
|
||||
var reader bytes.Buffer
|
||||
reader.ReadFrom(r.Body)
|
||||
assert.Equal(t, "[{\"comp_level\":\"qm\",\"set_number\":0,\"match_number\":2,\"alliances\":"+
|
||||
"{\"blue\":{\"score\":593,\"teams\":[\"frc10\",\"frc11\",\"frc12\"]},\"red\":{\"score\":312,"+
|
||||
"\"teams\":[\"frc7\",\"frc8\",\"frc9\"]}},\"score_breakdown\":{\"blue\":{\"auto\":292,"+
|
||||
"\"assist\":90,\"truss+catch\":70,\"teleop_goal+foul\":141},\"red\":{\"auto\":164,\"assist\":40,"+
|
||||
"\"truss+catch\":30,\"teleop_goal+foul\":78}},\"time_string\":\"4:10 PM\",\"time_utc\":"+
|
||||
"\"1970-01-01T00:10:00\"},{\"comp_level\":\"sf\",\"set_number\":2,\"match_number\":2,"+
|
||||
"\"alliances\":{\"blue\":{\"score\":null,\"teams\":[\"frc0\",\"frc0\",\"frc0\"]},\"red\":"+
|
||||
"{\"score\":null,\"teams\":[\"frc0\",\"frc0\",\"frc0\"]}},\"score_breakdown\":null,"+
|
||||
"\"time_string\":\"4:00 PM\",\"time_utc\":\"0001-01-01T00:00:00\"}]", reader.String())
|
||||
}))
|
||||
defer tbaServer.Close()
|
||||
tbaBaseUrl = tbaServer.URL
|
||||
@@ -82,11 +90,13 @@ func TestPublishRankings(t *testing.T) {
|
||||
|
||||
// Mock the TBA server.
|
||||
tbaServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var reader bytes.Buffer
|
||||
reader.ReadFrom(r.Body)
|
||||
assert.Equal(t, "{\"breakdowns\":[\"QS\",\"Assist\",\"Auto\",\"T\\u0026C\",\"G\\u0026F\"],\"rankings\":"+
|
||||
"[{\"team_key\":\"frc254\",\"rank\":1,\"wins\":10,\"losses\":0,\"ties\":0,\"played\":10,\"dqs\":0,"+
|
||||
"\"QS\":20,\"Assist\":1100,\"Auto\":625,\"T\\u0026C\":90,\"G\\u0026F\":554},{\"team_key\":\"frc1114\""+
|
||||
",\"rank\":2,\"wins\":9,\"losses\":1,\"ties\":0,\"played\":10,\"dqs\":0,\"QS\":18,\"Assist\":1100,"+
|
||||
"\"Auto\":625,\"T\\u0026C\":90,\"G\\u0026F\":554}]}", r.PostFormValue("rankings"))
|
||||
"\"Auto\":625,\"T\\u0026C\":90,\"G\\u0026F\":554}]}", reader.String())
|
||||
}))
|
||||
defer tbaServer.Close()
|
||||
tbaBaseUrl = tbaServer.URL
|
||||
@@ -106,8 +116,10 @@ func TestPublishAlliances(t *testing.T) {
|
||||
|
||||
// Mock the TBA server.
|
||||
tbaServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var reader bytes.Buffer
|
||||
reader.ReadFrom(r.Body)
|
||||
assert.Equal(t, "[[\"frc254\",\"frc469\",\"frc2848\",\"frc74\"],[\"frc1718\",\"frc2451\"]]",
|
||||
r.PostFormValue("alliances"))
|
||||
reader.String())
|
||||
}))
|
||||
defer tbaServer.Close()
|
||||
tbaBaseUrl = tbaServer.URL
|
||||
|
||||
Reference in New Issue
Block a user