Add tests for GetElection
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user