Add more test cases and add UniqueValues check

This commit is contained in:
2025-01-01 19:47:55 +01:00
parent 53aa4ab375
commit 941e9a36fb
3 changed files with 58 additions and 1 deletions

View File

@ -69,6 +69,11 @@ func isRequestValid(r *createElectionRequestWithValidator) bool {
r.CheckField(validator.GreaterThan(r.Tokens, 0), "tokens", "must be greater than 0")
r.CheckField(validator.After(r.ExpiresAt, time.Now()), "expiresAt", "must expire in a future date")
r.CheckField(validator.GreaterThan(len(r.Choices), 1), "choices", "there must be more than 1 choice")
r.CheckField(validator.UniqueValues(r.Choices), "choices", "must not contain duplicate values")
for _, choice := range r.Choices {
r.CheckField(validator.NotBlank(choice), "choice", "must not be blank")
}
if r.AreVotersKnown {
r.CheckField(