-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change tests to root folders
- Loading branch information
1 parent
08d88ed
commit 5d0907f
Showing
7 changed files
with
76 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package user_controllers_test | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
controllers "vanir/internal/app/presentation/controllers/users" | ||
"vanir/internal/pkg/config" | ||
"vanir/internal/pkg/data/db" | ||
"vanir/internal/pkg/data/models" | ||
"vanir/internal/pkg/helpers" | ||
"vanir/internal/pkg/protocols" | ||
_ "vanir/test" | ||
mocks "vanir/test/mocks" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRunCreateUserControllerTestCases(t *testing.T) { | ||
config.Setup() | ||
db.SetupDB() | ||
|
||
userServiceMock := &mocks.UserServiceMock{} | ||
|
||
controllerTestCases := []ControllerTestCase{ | ||
{ | ||
Name: "Should create user with valid data", | ||
|
@@ -33,10 +39,10 @@ func TestRunCreateUserControllerTestCases(t *testing.T) { | |
}, | ||
ExpectResponse: func(t *testing.T, response *protocols.HttpResponse) error { | ||
user, ok := response.Body.(*models.User) | ||
assert.True(t, ok) | ||
assert.NotNil(t, user.ID) | ||
assert.Equal(t, http.StatusCreated, response.StatusCode) | ||
assert.Equal(t, "[email protected]", user.Email) | ||
require.True(t, ok) | ||
require.NotNil(t, user.ID) | ||
require.Equal(t, http.StatusCreated, response.StatusCode) | ||
require.Equal(t, "[email protected]", user.Email) | ||
return nil | ||
}, | ||
AfterTest: func() error { | ||
|
@@ -66,7 +72,7 @@ func TestRunCreateUserControllerTestCases(t *testing.T) { | |
return nil | ||
}, | ||
ExpectResponse: func(t *testing.T, response *protocols.HttpResponse) error { | ||
assert.Equal(t, http.StatusInternalServerError, response.StatusCode) | ||
require.Equal(t, http.StatusInternalServerError, response.StatusCode) | ||
return nil | ||
}, | ||
AfterTest: func() error { | ||
|
@@ -85,18 +91,18 @@ func TestRunCreateUserControllerTestCases(t *testing.T) { | |
|
||
for _, testCase := range controllerTestCases { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
assert.NoError(t, testCase.BeforeTest()) | ||
require.NoError(t, testCase.BeforeTest()) | ||
|
||
createUserController := controllers.NewCreateUserController( | ||
createUserController := NewCreateUserController( | ||
userServiceMock, | ||
) | ||
request, ok := testCase.WhenRequest.(*protocols.HttpRequest) | ||
assert.True(t, ok) | ||
require.True(t, ok) | ||
|
||
response, _ := createUserController.Handle(request) | ||
|
||
assert.NoError(t, testCase.ExpectResponse(t, response)) | ||
assert.NoError(t, testCase.AfterTest()) | ||
require.NoError(t, testCase.ExpectResponse(t, response)) | ||
require.NoError(t, testCase.AfterTest()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
package user_controllers_test | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
controllers "vanir/internal/app/presentation/controllers/users" | ||
"vanir/internal/pkg/config" | ||
"vanir/internal/pkg/data/db" | ||
"vanir/internal/pkg/data/models" | ||
"vanir/internal/pkg/helpers" | ||
"vanir/internal/pkg/protocols" | ||
data_test "vanir/test/data" | ||
mocks "vanir/test/mocks" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRunGetUserControllerTestCases(t *testing.T) { | ||
type ControllerTestCase data_test.ControllerTestCase | ||
|
||
func TestGetUserControllerTestCases(t *testing.T) { | ||
config.Setup() | ||
db.SetupDB() | ||
|
||
userServiceMock := &mocks.UserServiceMock{} | ||
|
||
controllerTestCases := []ControllerTestCase{ | ||
{ | ||
Name: "Should return user when service returns the user with valid id", | ||
|
@@ -29,10 +39,10 @@ func TestRunGetUserControllerTestCases(t *testing.T) { | |
}, | ||
ExpectResponse: func(t *testing.T, response *protocols.HttpResponse) error { | ||
user, ok := response.Body.(*models.User) | ||
assert.True(t, ok) | ||
assert.NotNil(t, user.ID) | ||
assert.Equal(t, http.StatusOK, response.StatusCode) | ||
assert.Equal(t, "[email protected]", user.Email) | ||
require.True(t, ok) | ||
require.NotNil(t, user.ID) | ||
require.Equal(t, http.StatusOK, response.StatusCode) | ||
require.Equal(t, "[email protected]", user.Email) | ||
return nil | ||
}, | ||
AfterTest: func() error { | ||
|
@@ -54,7 +64,7 @@ func TestRunGetUserControllerTestCases(t *testing.T) { | |
return nil | ||
}, | ||
ExpectResponse: func(t *testing.T, response *protocols.HttpResponse) error { | ||
assert.Equal(t, http.StatusInternalServerError, response.StatusCode) | ||
require.Equal(t, http.StatusInternalServerError, response.StatusCode) | ||
return nil | ||
}, | ||
AfterTest: func() error { | ||
|
@@ -68,18 +78,18 @@ func TestRunGetUserControllerTestCases(t *testing.T) { | |
|
||
for _, testCase := range controllerTestCases { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
assert.NoError(t, testCase.BeforeTest()) | ||
require.NoError(t, testCase.BeforeTest()) | ||
|
||
updateUserController := controllers.NewGetUserController( | ||
updateUserController := NewGetUserController( | ||
userServiceMock, | ||
) | ||
request, ok := testCase.WhenRequest.(*protocols.HttpRequest) | ||
assert.True(t, ok) | ||
require.True(t, ok) | ||
|
||
response, _ := updateUserController.Handle(request) | ||
|
||
assert.NoError(t, testCase.ExpectResponse(t, response)) | ||
assert.NoError(t, testCase.AfterTest()) | ||
require.NoError(t, testCase.ExpectResponse(t, response)) | ||
require.NoError(t, testCase.AfterTest()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
package user_controllers_test | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
controllers "vanir/internal/app/presentation/controllers/users" | ||
"vanir/internal/pkg/config" | ||
"vanir/internal/pkg/data/db" | ||
"vanir/internal/pkg/data/models" | ||
"vanir/internal/pkg/helpers" | ||
"vanir/internal/pkg/protocols" | ||
mocks "vanir/test/mocks" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRunUpdateUserControllerTestCases(t *testing.T) { | ||
config.Setup() | ||
db.SetupDB() | ||
|
||
userServiceMock := &mocks.UserServiceMock{} | ||
|
||
controllerTestCases := []ControllerTestCase{ | ||
{ | ||
Name: "Should update user with valid data", | ||
|
@@ -33,10 +40,10 @@ func TestRunUpdateUserControllerTestCases(t *testing.T) { | |
}, | ||
ExpectResponse: func(t *testing.T, response *protocols.HttpResponse) error { | ||
user, ok := response.Body.(*models.User) | ||
assert.True(t, ok) | ||
assert.NotNil(t, user.ID) | ||
assert.Equal(t, http.StatusOK, response.StatusCode) | ||
assert.Equal(t, "[email protected]", user.Email) | ||
require.True(t, ok) | ||
require.NotNil(t, user.ID) | ||
require.Equal(t, http.StatusOK, response.StatusCode) | ||
require.Equal(t, "[email protected]", user.Email) | ||
return nil | ||
}, | ||
AfterTest: func() error { | ||
|
@@ -62,7 +69,7 @@ func TestRunUpdateUserControllerTestCases(t *testing.T) { | |
return nil | ||
}, | ||
ExpectResponse: func(t *testing.T, response *protocols.HttpResponse) error { | ||
assert.Equal(t, http.StatusInternalServerError, response.StatusCode) | ||
require.Equal(t, http.StatusInternalServerError, response.StatusCode) | ||
return nil | ||
}, | ||
AfterTest: func() error { | ||
|
@@ -76,18 +83,18 @@ func TestRunUpdateUserControllerTestCases(t *testing.T) { | |
|
||
for _, testCase := range controllerTestCases { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
assert.NoError(t, testCase.BeforeTest()) | ||
require.NoError(t, testCase.BeforeTest()) | ||
|
||
updateUserController := controllers.NewUpdateUserController( | ||
updateUserController := NewUpdateUserController( | ||
userServiceMock, | ||
) | ||
request, ok := testCase.WhenRequest.(*protocols.HttpRequest) | ||
assert.True(t, ok) | ||
require.True(t, ok) | ||
|
||
response, _ := updateUserController.Handle(request) | ||
|
||
assert.NoError(t, testCase.ExpectResponse(t, response)) | ||
assert.NoError(t, testCase.AfterTest()) | ||
require.NoError(t, testCase.ExpectResponse(t, response)) | ||
require.NoError(t, testCase.AfterTest()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.