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