Fix maxVoters check and add unit tests

This commit is contained in:
2025-01-21 09:24:51 +01:00
parent 5570dca6c9
commit a1af7a48b2
2 changed files with 18 additions and 2 deletions

View File

@ -82,7 +82,7 @@ func TestCreateElection(t *testing.T) {
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Now().Add(24 * time.Hour),
AreVotersKnown: false,
MaxVoters: 10,
MaxVoters: 1000,
Name: "Guy of the year",
Tokens: 100,
},
@ -179,6 +179,19 @@ func TestCreateElection(t *testing.T) {
},
expectedCode: http.StatusUnprocessableEntity,
},
{
name: "Invalid request for known voters election (max voters greater than 100)",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha", ""},
ExpiresAt: time.Now().Add(24 * time.Hour),
AreVotersKnown: true,
MaxVoters: 101,
Name: "Guy of the year",
Tokens: 100,
},
expectedCode: http.StatusUnprocessableEntity,
},
}
for _, tt := range tests {