Add variable for urlPath

This commit is contained in:
2025-01-02 17:44:44 +01:00
parent d4fc6a54cf
commit bbbdb637b0

View File

@ -15,6 +15,8 @@ func TestCreateElection(t *testing.T) {
server := newTestServer(t, app.routes())
defer server.Close()
path := "/election"
tests := []struct {
name string
urlPath string
@ -23,7 +25,7 @@ func TestCreateElection(t *testing.T) {
}{
{
name: "Valid request (small name, other language)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"宮本武蔵", "伊東一刀斎"},
ExpiresAt: time.Now().Add(24 * time.Hour),
@ -36,7 +38,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Valid request (voters unknown with unlimited voters)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Now().Add(24 * time.Hour),
@ -49,7 +51,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Valid request (with 3 choices)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha", "You"},
ExpiresAt: time.Now().Add(24 * time.Hour),
@ -62,7 +64,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Valid request (voters unknown with max voters)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Now().Add(24 * time.Hour),
@ -75,7 +77,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Valid request (voters known with max voters)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Now().Add(24 * time.Hour),
@ -88,7 +90,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Invalid request (not enough choices)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi"},
ExpiresAt: time.Unix(0, 0),
@ -101,7 +103,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Invalid request (expiresAt is not in the future)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Unix(0, 0),
@ -114,7 +116,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Invalid request (max voters must be greater than 0 for known elections)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Unix(0, 0),
@ -127,7 +129,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Invalid request (blank name)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha"},
ExpiresAt: time.Unix(0, 0),
@ -140,7 +142,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Invalid request (choices are not unique)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Gandhi"},
ExpiresAt: time.Now().Add(24 * time.Hour),
@ -153,7 +155,7 @@ func TestCreateElection(t *testing.T) {
},
{
name: "Invalid request (choices contain blank entries)",
urlPath: "/election",
urlPath: path,
body: api.CreateElectionRequest{
Choices: []string{"Gandhi", "Buddha", ""},
ExpiresAt: time.Now().Add(24 * time.Hour),