From 60d1bb382c12e3db27a8aecec96361038af37db8 Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 17 Jan 2025 13:59:37 +0100 Subject: [PATCH] Write TestGetElectionResults_NotFound --- cmd/web/handlers_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/web/handlers_test.go b/cmd/web/handlers_test.go index 300bfe0..af8937c 100644 --- a/cmd/web/handlers_test.go +++ b/cmd/web/handlers_test.go @@ -786,4 +786,24 @@ func TestGetElectionResults(t *testing.T) { } } -// TODO write test for not found getElectionResults +func TestGetElectionResults_NotFound(t *testing.T) { + app := newTestApplication(t) + server := newTestServer(t, app.routes()) + defer server.Close() + + mockVotes := app.votes.(*mockVoteModel) + mockVotes. + On("GetByElection", mock.Anything). + Return(&[]models.Vote{}, sql.ErrNoRows) + + path := baseUri + "election/1/results" + code, _, body := server.get(t, path) + + assert.Equal(t, http.StatusNotFound, code) + + var response api.ElectionResultsResponse + err := json.Unmarshal([]byte(body), &response) + if err != nil { + t.Fatal(err) + } +}