Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
solo21-12 committed Aug 15, 2024
1 parent a123bd7 commit ae48086
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions tests/task_tests/controller_tests/task_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
// "bytes"
// "bytes"
// "encoding/json"
"bytes"
"encoding/json"
// "bytes"
// "encoding/json"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -52,68 +52,68 @@ func (suite *TaskControllerSuite) TearDownSuite() {
suite.ctrl.Finish()
}

func (suite *TaskControllerSuite) TestCreateTask_Success() {
taskCreate := domain.TaskCreateDTO{
Title: "New Task",
Description: "Description",
DueDate: fixedTime,
Status: "pending",
}
taskDTO := domain.TaskDTO{
ID: primitive.NewObjectID(),
Title: "New Task",
Description: "Description",
DueDate: fixedTime,
Status: "pending",
}

suite.usecase.
EXPECT().
CreateTask(gomock.Eq(taskCreate), gomock.Any()).
Return(taskDTO, nil).
Times(1)

inputJSON, err := json.Marshal(taskCreate)
suite.NoError(err)

response, err := http.Post(suite.server.URL+"/tasks", "application/json", bytes.NewBuffer(inputJSON))
suite.NoError(err)

defer response.Body.Close()

// Check the response status
suite.Equal(http.StatusCreated, response.StatusCode)

// Optional: Check the response body if needed
var responseDTO domain.TaskDTO
err = json.NewDecoder(response.Body).Decode(&responseDTO)
suite.NoError(err)
suite.Equal(taskDTO, responseDTO)
}

func (suite *TaskControllerSuite) TestCreateTask_Failure() {

taskCreate := domain.TaskCreateDTO{
Title: "New Task",
Description: "Description",
DueDate: fixedTime,
Status: "pending",
}

inputJSON, err := json.Marshal(taskCreate)
suite.NoError(err)

suite.usecase.
EXPECT().
CreateTask(gomock.Any(), gomock.Any()).
Return(domain.TaskDTO{}, &domain.ErrorResponse{Code: http.StatusBadRequest, Message: "Bad Request"})

resp, err := http.Post(suite.server.URL+"/tasks", "application/json", bytes.NewBuffer(inputJSON))
if err != nil {
suite.T().Fatal(err)
}
suite.Equal(http.StatusBadRequest, resp.StatusCode)
}
// func (suite *TaskControllerSuite) TestCreateTask_Success() {
// taskCreate := domain.TaskCreateDTO{
// Title: "New Task",
// Description: "Description",
// DueDate: fixedTime,
// Status: "pending",
// }
// taskDTO := domain.TaskDTO{
// ID: primitive.NewObjectID(),
// Title: "New Task",
// Description: "Description",
// DueDate: fixedTime,
// Status: "pending",
// }

// suite.usecase.
// EXPECT().
// CreateTask(gomock.Eq(taskCreate), gomock.Any()).
// Return(taskDTO, nil).
// Times(1)

// inputJSON, err := json.Marshal(taskCreate)
// suite.NoError(err)

// response, err := http.Post(suite.server.URL+"/tasks", "application/json", bytes.NewBuffer(inputJSON))
// suite.NoError(err)

// defer response.Body.Close()

// // Check the response status
// suite.Equal(http.StatusCreated, response.StatusCode)

// // Optional: Check the response body if needed
// var responseDTO domain.TaskDTO
// err = json.NewDecoder(response.Body).Decode(&responseDTO)
// suite.NoError(err)
// suite.Equal(taskDTO, responseDTO)
// }

// func (suite *TaskControllerSuite) TestCreateTask_Failure() {

// taskCreate := domain.TaskCreateDTO{
// Title: "New Task",
// Description: "Description",
// DueDate: fixedTime,
// Status: "pending",
// }

// inputJSON, err := json.Marshal(taskCreate)
// suite.NoError(err)

// suite.usecase.
// EXPECT().
// CreateTask(gomock.Any(), gomock.Any()).
// Return(domain.TaskDTO{}, &domain.ErrorResponse{Code: http.StatusBadRequest, Message: "Bad Request"})

// resp, err := http.Post(suite.server.URL+"/tasks", "application/json", bytes.NewBuffer(inputJSON))
// if err != nil {
// suite.T().Fatal(err)
// }
// suite.Equal(http.StatusBadRequest, resp.StatusCode)
// }

func (suite *TaskControllerSuite) TestGetAllTasks_Success() {

Expand Down

0 comments on commit ae48086

Please sign in to comment.