Add some more tests and implement getElection
This commit is contained in:
@ -192,6 +192,50 @@ func TestCreateElection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateElection_KnownVoters(t *testing.T) {
|
||||
app := newTestApplication(t)
|
||||
server := newTestServer(t, app.routes())
|
||||
defer server.Close()
|
||||
|
||||
mockElections := app.elections.(*mockElectionModel)
|
||||
mockElections.
|
||||
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
||||
Return(1, nil)
|
||||
|
||||
mockVoters := app.voters.(*mockVoterModel)
|
||||
mockVoters.
|
||||
On("InsertMultiple", mock.Anything, mock.Anything).
|
||||
Return([]int{1}, nil)
|
||||
|
||||
path := baseUri + "election"
|
||||
requestBody := api.CreateElectionRequest{
|
||||
Choices: []string{"宮本武蔵", "伊東一刀斎"},
|
||||
ExpiresAt: time.Now().Add(24 * time.Hour),
|
||||
AreVotersKnown: true,
|
||||
MaxVoters: 100,
|
||||
Name: "強",
|
||||
Tokens: 100,
|
||||
}
|
||||
requestBodyJson, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
code, _, body := server.post(t, path, bytes.NewReader(requestBodyJson))
|
||||
|
||||
assert.Equal(t, http.StatusOK, code)
|
||||
|
||||
var voterIdentities struct {
|
||||
VoterIdentities []string
|
||||
}
|
||||
err = json.Unmarshal([]byte(body), &voterIdentities)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Len(t, voterIdentities.VoterIdentities, 100)
|
||||
}
|
||||
|
||||
func TestCreateElection_ServerError(t *testing.T) {
|
||||
app := newTestApplication(t)
|
||||
server := newTestServer(t, app.routes())
|
||||
|
Reference in New Issue
Block a user