Add tests for GetElection

This commit is contained in:
2025-01-17 14:55:54 +01:00
parent 410e8f39d3
commit 62562272f1

View File

@ -851,3 +851,44 @@ func TestGetElectionResults_NotFound(t *testing.T) {
t.Fatal(err)
}
}
func TestGetElection_Found(t *testing.T) {
app := newTestApplication(t)
server := newTestServer(t, app.routes())
defer server.Close()
mockElections := app.elections.(*mockElectionModel)
mockElections.
On("GetById", mock.Anything).
Return(&models.Election{
ID: 1,
Name: "Guy of the year",
Tokens: 100,
AreVotersKnown: false,
MaxVoters: 10,
CreatedAt: time.UnixMilli(1),
ExpiresAt: time.UnixMilli(100000),
Choices: []string{"Gandhi", "Buddha"},
}, nil)
path := baseUri + "election/1"
code, _, _ := server.get(t, path)
assert.Equal(t, http.StatusOK, code)
}
func TestGetElection_NotFound(t *testing.T) {
app := newTestApplication(t)
server := newTestServer(t, app.routes())
defer server.Close()
mockElections := app.elections.(*mockElectionModel)
mockElections.
On("GetById", mock.Anything).
Return((*models.Election)(nil), sql.ErrNoRows)
path := baseUri + "election/1"
code, _, _ := server.get(t, path)
assert.Equal(t, http.StatusNotFound, code)
}