Put API behind /api
This commit is contained in:
@ -24,7 +24,7 @@ func TestCreateElection(t *testing.T) {
|
|||||||
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
||||||
Return(1, nil)
|
Return(1, nil)
|
||||||
|
|
||||||
path := "/election"
|
path := "/api/election"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -200,7 +200,7 @@ func TestCreateElection_ServerError(t *testing.T) {
|
|||||||
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
||||||
Return(0, fmt.Errorf(""))
|
Return(0, fmt.Errorf(""))
|
||||||
|
|
||||||
path := "/election"
|
path := "/api/election"
|
||||||
requestBody := api.CreateElectionRequest{
|
requestBody := api.CreateElectionRequest{
|
||||||
Choices: []string{"宮本武蔵", "伊東一刀斎"},
|
Choices: []string{"宮本武蔵", "伊東一刀斎"},
|
||||||
ExpiresAt: time.Now().Add(24 * time.Hour),
|
ExpiresAt: time.Now().Add(24 * time.Hour),
|
||||||
@ -254,7 +254,7 @@ func TestCreateVotes_UnknownVotersElection(t *testing.T) {
|
|||||||
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
On("Insert", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
|
||||||
Return(1, nil)
|
Return(1, nil)
|
||||||
|
|
||||||
path := "/election/1/votes"
|
path := "/api/election/1/votes"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -359,7 +359,7 @@ func TestCreateVotes_KnownVotersElection(t *testing.T) {
|
|||||||
On("Exists", mock.Anything, mock.Anything).
|
On("Exists", mock.Anything, mock.Anything).
|
||||||
Return(false, nil)
|
Return(false, nil)
|
||||||
|
|
||||||
path := "/election/1/votes"
|
path := "/api/election/1/votes"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -467,7 +467,7 @@ func TestCreateVotes_NonExistingElection(t *testing.T) {
|
|||||||
On("GetById", mock.Anything).
|
On("GetById", mock.Anything).
|
||||||
Return((*models.Election)(nil), sql.ErrNoRows)
|
Return((*models.Election)(nil), sql.ErrNoRows)
|
||||||
|
|
||||||
path := "/election/1/votes"
|
path := "/api/election/1/votes"
|
||||||
requestBody := api.CreateVotesRequest{
|
requestBody := api.CreateVotesRequest{
|
||||||
Choices: []struct {
|
Choices: []struct {
|
||||||
ChoiceText string `json:"choiceText"`
|
ChoiceText string `json:"choiceText"`
|
||||||
@ -498,7 +498,7 @@ func TestCreateVotes_NonNumberElectionID(t *testing.T) {
|
|||||||
On("GetById", mock.Anything).
|
On("GetById", mock.Anything).
|
||||||
Return((*models.Election)(nil), sql.ErrNoRows)
|
Return((*models.Election)(nil), sql.ErrNoRows)
|
||||||
|
|
||||||
path := "/election/1a/votes"
|
path := "/api/election/1a/votes"
|
||||||
requestBody := api.CreateVotesRequest{
|
requestBody := api.CreateVotesRequest{
|
||||||
Choices: []struct {
|
Choices: []struct {
|
||||||
ChoiceText string `json:"choiceText"`
|
ChoiceText string `json:"choiceText"`
|
||||||
@ -555,8 +555,8 @@ func TestCreateVotes_AlreadyVoted(t *testing.T) {
|
|||||||
On("Exists", mock.Anything, mock.Anything).
|
On("Exists", mock.Anything, mock.Anything).
|
||||||
Return(true, nil)
|
Return(true, nil)
|
||||||
|
|
||||||
knownVotersElectionPath := "/election/1/votes"
|
knownVotersElectionPath := "/api/election/1/votes"
|
||||||
unknownVotersElectionPath := "/election/2/votes"
|
unknownVotersElectionPath := "/api/election/2/votes"
|
||||||
voterIdentity := "anything"
|
voterIdentity := "anything"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -640,7 +640,7 @@ func TestCreateVotes_UnknownVotersElectionMaxVotersReached(t *testing.T) {
|
|||||||
On("CountByElection", mock.Anything).
|
On("CountByElection", mock.Anything).
|
||||||
Return(10, nil)
|
Return(10, nil)
|
||||||
|
|
||||||
path := "/election/1/votes"
|
path := "/api/election/1/votes"
|
||||||
requestBody := api.CreateVotesRequest{
|
requestBody := api.CreateVotesRequest{
|
||||||
Choices: []struct {
|
Choices: []struct {
|
||||||
ChoiceText string `json:"choiceText"`
|
ChoiceText string `json:"choiceText"`
|
||||||
@ -691,7 +691,7 @@ func TestCreateVotes_ExpiredElection(t *testing.T) {
|
|||||||
On("CountByElection", mock.Anything).
|
On("CountByElection", mock.Anything).
|
||||||
Return(10, nil)
|
Return(10, nil)
|
||||||
|
|
||||||
path := "/election/1/votes"
|
path := "/api/election/1/votes"
|
||||||
requestBody := api.CreateVotesRequest{
|
requestBody := api.CreateVotesRequest{
|
||||||
Choices: []struct {
|
Choices: []struct {
|
||||||
ChoiceText string `json:"choiceText"`
|
ChoiceText string `json:"choiceText"`
|
||||||
|
@ -24,6 +24,7 @@ func (app *application) routes() http.Handler {
|
|||||||
|
|
||||||
api.HandlerWithOptions(app, api.StdHTTPServerOptions{
|
api.HandlerWithOptions(app, api.StdHTTPServerOptions{
|
||||||
BaseRouter: mux,
|
BaseRouter: mux,
|
||||||
|
BaseURL: "/api",
|
||||||
ErrorHandlerFunc: app.badRequestError,
|
ErrorHandlerFunc: app.badRequestError,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@
|
|||||||
choices: this.election.choices.filter(choice => choice.trim() !== "") // Filter out empty choices
|
choices: this.election.choices.filter(choice => choice.trim() !== "") // Filter out empty choices
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch("/election", {
|
fetch("/api/election", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
|
Reference in New Issue
Block a user