Skip to content

Commit

Permalink
Don't use lineup from Nexus unless all positions are filled (fixes #162
Browse files Browse the repository at this point in the history
…).
  • Loading branch information
patfair committed Oct 31, 2023
1 parent 888b8d4 commit 9e73c8c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions partner/nexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ func (client *NexusClient) GetLineup(tbaMatchKey model.TbaMatchKey) (*[6]int, er
lineup[4], _ = strconv.Atoi(nexusLineup.Blue[1])
lineup[5], _ = strconv.Atoi(nexusLineup.Blue[2])

// Check that each spot is filled with a valid team number; otherwise return an error.
for _, team := range lineup {
if team == 0 {
return nil, fmt.Errorf("Lineup not yet submitted")
}
}

return &lineup, err
}

Expand Down
18 changes: 18 additions & 0 deletions partner/nexus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func TestGetLineup(t *testing.T) {
assert.Contains(t, r.URL.String(), "/v1/my_event_code/")
if strings.Contains(r.URL.String(), "/v1/my_event_code/p1/lineup") {
w.Write([]byte("{\"red\":[\"101\",\"102\",\"103\"],\"blue\":[\"104\",\"105\",\"106\"]}"))
} else if strings.Contains(r.URL.String(), "/v1/my_event_code/p2/lineup") {
w.Write([]byte("{\"blue\":[\"104\",\"105\",\"106\"]}"))
} else if strings.Contains(r.URL.String(), "/v1/my_event_code/p3/lineup") {
w.Write([]byte("{}"))
} else {
http.Error(w, "Match not found", 404)
}
Expand All @@ -38,4 +42,18 @@ func TestGetLineup(t *testing.T) {
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "Match not found")
}

tbaMatchKey = model.TbaMatchKey{CompLevel: "p", SetNumber: 0, MatchNumber: 2}
lineup, err = client.GetLineup(tbaMatchKey)
assert.Nil(t, lineup)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "Lineup not yet submitted")
}

tbaMatchKey = model.TbaMatchKey{CompLevel: "p", SetNumber: 0, MatchNumber: 3}
lineup, err = client.GetLineup(tbaMatchKey)
assert.Nil(t, lineup)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "Lineup not yet submitted")
}
}

0 comments on commit 9e73c8c

Please sign in to comment.