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