Add tests for createElection handler

This commit is contained in:
2024-12-31 14:35:31 +01:00
parent 57bd72506b
commit c9b7a5796e
4 changed files with 128 additions and 46 deletions

View File

@ -1,18 +1,19 @@
package main
import (
"code.dlmw.ch/dlmw/qv/internal/models"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func newTestApplication(t *testing.T) *application {
return &application{
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
elections: &models.ElectionModel{},
elections: &mockElectionModel{},
voters: &mockVoterModel{},
}
}
@ -39,3 +40,17 @@ func (ts *testServer) post(t *testing.T, urlPath string, body io.Reader) (int, h
return res.StatusCode, res.Header, string(responseBody)
}
type mockElectionModel struct {
}
func (e *mockElectionModel) Insert(name string, tokens int, areVotersKnown bool, maxVoters int, choices []string, expiresAt time.Time) (int, error) {
return 1, nil
}
type mockVoterModel struct {
}
func (v *mockVoterModel) Insert(identity string, electionID int) (int, error) {
return 1, nil
}