Skip to content

Commit

Permalink
Disallow changing number of playoff alliances after alliance selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Jun 26, 2024
1 parent 0e300d0 commit 1b7f953
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions web/setup_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
playoffType = model.DoubleEliminationPlayoff
numAlliances = 8
}
if eventSettings.PlayoffType != playoffType {
if eventSettings.PlayoffType != playoffType || eventSettings.NumPlayoffAlliances != numAlliances {
alliances, err := web.arena.Database.GetAllAlliances()
if err != nil {
handleWebErr(w, err)
return
}
if len(alliances) > 0 {
web.renderSettings(w, r, "Cannot change playoff type after alliance selection has been finalized.")
web.renderSettings(
w, r, "Cannot change playoff type or size after alliance selection has been finalized.",
)
return
}
}
Expand Down
12 changes: 9 additions & 3 deletions web/setup_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ func TestSetupSettingsDoubleElimination(t *testing.T) {

func TestSetupSettingsInvalidValues(t *testing.T) {
web := setupTestWeb(t)
recorder := web.postHttpResponse("/setup/settings", "playoffType=SingleEliminationPlayoff&numPlayoffAlliances=8")
assert.Equal(t, 303, recorder.Code)

// Invalid number of alliances.
recorder := web.postHttpResponse("/setup/settings", "playoffType=SingleEliminationPlayoff&numAlliances=1")
recorder = web.postHttpResponse("/setup/settings", "playoffType=SingleEliminationPlayoff&numAlliances=1")
assert.Contains(t, recorder.Body.String(), "must be between 2 and 16")

// Changing the playoff type after alliance selection is finalized.
assert.Nil(t, web.arena.Database.CreateAlliance(&model.Alliance{Id: 1}))
recorder = web.postHttpResponse("/setup/settings", "playoffType=SingleEliminationPlayoff&numPlayoffAlliances=8")
assert.Contains(t, recorder.Body.String(), "Cannot change playoff type after alliance selection")
recorder = web.postHttpResponse("/setup/settings", "playoffType=DoubleEliminationPlayoff")
assert.Contains(t, recorder.Body.String(), "Cannot change playoff type or size after alliance selection")

// Changing the playoff size after alliance selection is finalized.
recorder = web.postHttpResponse("/setup/settings", "numPlayoffAlliances=2")
assert.Contains(t, recorder.Body.String(), "Cannot change playoff type or size after alliance selection")
}

func TestSetupSettingsClearDb(t *testing.T) {
Expand Down

0 comments on commit 1b7f953

Please sign in to comment.