Fix maxVoters check and add unit tests
This commit is contained in:
@ -72,13 +72,16 @@ func (r *createElectionRequestWithValidator) isValid() bool {
|
||||
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")
|
||||
r.CheckField(validator.LesserThan(r.MaxVoters, 101), "maxVoters", "cannot create a known-voters election with more than 100 voters")
|
||||
|
||||
for _, choice := range r.Choices {
|
||||
r.CheckField(validator.NotBlank(choice), "choice", "must not be blank")
|
||||
}
|
||||
|
||||
if r.AreVotersKnown {
|
||||
r.CheckField(validator.LesserThan(r.MaxVoters, 101),
|
||||
"maxVoters",
|
||||
"cannot create a known-voters election with more than 100 voters",
|
||||
)
|
||||
r.CheckField(
|
||||
validator.GreaterThan(r.MaxVoters, 0),
|
||||
"maxVoters",
|
||||
|
Reference in New Issue
Block a user