Deleting questions and adding tests for deleteing
This commit is contained in:
@@ -458,4 +458,40 @@ func TestVoterAlreadyVoted(t *testing.T) {
|
||||
if err != ErrVoterAlreadyVoted {
|
||||
t.Fatalf("Expected ErrVoterAlreadyVoted, but got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeletePollByQuestion(t *testing.T) {
|
||||
// Preload the database with members, polls, and voters
|
||||
tmp_db, err := os.CreateTemp("", "vote_test.*.db")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temporary database: %v", err)
|
||||
}
|
||||
defer os.Remove(tmp_db.Name())
|
||||
|
||||
init_conf := &config.Config{
|
||||
DBPath: string(tmp_db.Name()),
|
||||
}
|
||||
config.SetConfig(init_conf)
|
||||
|
||||
err = PreLoadDB()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to preload database: %v", err)
|
||||
}
|
||||
|
||||
// Get a question from the new_polls array
|
||||
testQuestion := new_polls[0].question
|
||||
|
||||
// Delete the poll by question
|
||||
err = DeletePollByQuestion(testQuestion)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to delete poll by question: %v", err)
|
||||
}
|
||||
|
||||
// Verify that the poll was deleted
|
||||
_, err = GetPollByQuestion(testQuestion)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error when getting deleted poll, but got none")
|
||||
} else if err != ErrPollNotFound {
|
||||
t.Fatalf("Expected ErrPollNotFound, but got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user