Write some tests for createVotes before refactoring

This commit is contained in:
2025-01-09 15:35:16 +01:00
parent bf3368b736
commit d77bef4bda
3 changed files with 285 additions and 13 deletions

View File

@ -54,30 +54,27 @@ func (e *mockElectionModel) Insert(name string, tokens int, areVotersKnown bool,
}
func (e *mockElectionModel) GetById(id int) (*models.Election, error) {
return &models.Election{
ID: id,
Name: "Guy of the year",
Tokens: 100,
AreVotersKnown: false,
MaxVoters: 10,
CreatedAt: time.Now(),
ExpiresAt: time.Now().Add(100 * time.Hour),
}, nil
args := e.Called(id)
return args.Get(0).(*models.Election), args.Error(1)
}
type mockVoterModel struct {
mock.Mock
}
func (v *mockVoterModel) Insert(identity string, electionID int) (int, error) {
return 1, nil
args := v.Called(identity, electionID)
return args.Int(0), args.Error(1)
}
func (v *mockVoterModel) CountByElection(electionID int) (int, error) {
return 10, nil
args := v.Called(electionID)
return args.Int(0), args.Error(1)
}
func (v *mockVoterModel) Exists(voterIdentity string, electionID int) (bool, error) {
return true, nil
args := v.Called(voterIdentity, electionID)
return args.Bool(0), args.Error(1)
}
type mockVoteModel struct {
@ -90,5 +87,6 @@ func (v *mockVoteModel) Insert(voterIdentity string, electionId int, choiceText
}
func (v *mockVoteModel) Exists(voterIdentity string, electionID int) (bool, error) {
return true, nil
args := v.Called(voterIdentity, electionID)
return args.Bool(0), args.Error(1)
}