Write some tests for createVotes before refactoring

This commit is contained in:
2025-01-09 15:35:16 +01:00
parent bf3368b736
commit d77bef4bda
3 changed files with 285 additions and 13 deletions

View File

@ -184,6 +184,16 @@ func (app *application) createVotes(w http.ResponseWriter, r *http.Request) {
app.unprocessableEntityErrorSingle(w, fmt.Errorf("you already voted"))
return ""
}
voterExists, err := app.voters.Exists(voterIdentity, election.ID)
if err != nil {
app.serverError(w, r, err)
return ""
}
if !voterExists {
app.unprocessableEntityErrorSingle(w, fmt.Errorf("invalid voter identity"))
return ""
}
} else {
voterIdentity = r.RemoteAddr