diff --git a/cmd/web/handlers_test.go b/cmd/web/handlers_test.go index 242cfac..2b39bbc 100644 --- a/cmd/web/handlers_test.go +++ b/cmd/web/handlers_test.go @@ -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) +}