Add more test cases and add UniqueValues check
This commit is contained in:
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
api "code.dlmw.ch/dlmw/qv/internal"
|
||||
"code.dlmw.ch/dlmw/qv/internal"
|
||||
"encoding/json"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
@ -47,6 +47,19 @@ func TestCreateElection(t *testing.T) {
|
||||
},
|
||||
expectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "Valid request (with 3 choices)",
|
||||
urlPath: "/election",
|
||||
body: api.CreateElectionRequest{
|
||||
Choices: []string{"Gandhi", "Buddha", "You"},
|
||||
ExpiresAt: time.Now().Add(24 * time.Hour),
|
||||
AreVotersKnown: false,
|
||||
MaxVoters: 0,
|
||||
Name: "Guy of the year",
|
||||
Tokens: 100,
|
||||
},
|
||||
expectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "Valid request (voters unknown with max voters)",
|
||||
urlPath: "/election",
|
||||
@ -125,6 +138,32 @@ func TestCreateElection(t *testing.T) {
|
||||
},
|
||||
expectedCode: http.StatusUnprocessableEntity,
|
||||
},
|
||||
{
|
||||
name: "Invalid request (choices are not unique)",
|
||||
urlPath: "/election",
|
||||
body: api.CreateElectionRequest{
|
||||
Choices: []string{"Gandhi", "Gandhi"},
|
||||
ExpiresAt: time.Now().Add(24 * time.Hour),
|
||||
AreVotersKnown: false,
|
||||
MaxVoters: 0,
|
||||
Name: "Guy of the year",
|
||||
Tokens: 100,
|
||||
},
|
||||
expectedCode: http.StatusUnprocessableEntity,
|
||||
},
|
||||
{
|
||||
name: "Invalid request (choices contain blank entries)",
|
||||
urlPath: "/election",
|
||||
body: api.CreateElectionRequest{
|
||||
Choices: []string{"Gandhi", "Buddha", ""},
|
||||
ExpiresAt: time.Now().Add(24 * time.Hour),
|
||||
AreVotersKnown: false,
|
||||
MaxVoters: 0,
|
||||
Name: "Guy of the year",
|
||||
Tokens: 100,
|
||||
},
|
||||
expectedCode: http.StatusUnprocessableEntity,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
Reference in New Issue
Block a user