Skip to content

Commit

Permalink
test: add create user test (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina authored May 20, 2024
1 parent 70491af commit fe57407
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions core/user/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ func TestService_Create(t *testing.T) {

tests := []struct {
name string
email string
user user.User
setup func(t *testing.T) *user.Service
urn string
want user.User
wantErr error
}{
{
name: "CreateUserWithUpperCase",
name: "CreateUserWithUpperCase",
email: "[email protected]",
user: user.User{
Name: "John Doe",
Email: "[email protected]",
Expand Down Expand Up @@ -66,7 +68,8 @@ func TestService_Create(t *testing.T) {
wantErr: nil,
},
{
name: "CreateUserSelfRegister",
name: "CreateUserSelfRegister",
email: "[email protected]",
user: user.User{
Name: "Jane Doe",
Email: "[email protected]",
Expand Down Expand Up @@ -100,7 +103,8 @@ func TestService_Create(t *testing.T) {
wantErr: nil,
},
{
name: "CreateUserInvalidHeader",
name: "CreateUserInvalidHeader",
email: "[email protected]",
user: user.User{
Name: "John Doe",
Email: "[email protected]",
Expand All @@ -117,6 +121,24 @@ func TestService_Create(t *testing.T) {
},
wantErr: user.ErrInvalidEmail,
},
{
name: "CreateUserMissingHeader",
user: user.User{
Name: "John Doe",
Email: "[email protected]",
},
setup: func(t *testing.T) *user.Service {
t.Helper()
repository := &mocks.Repository{}
activityService := &mocks.ActivityService{}
logger := shieldlogger.InitLogger(logger.Config{})
repository.EXPECT().
GetByEmail(mock.Anything, "").
Return(user.User{}, user.ErrMissingEmail)
return user.NewService(logger, repository, activityService)
},
wantErr: user.ErrMissingEmail,
},
}

for _, tt := range tests {
Expand All @@ -127,7 +149,7 @@ func TestService_Create(t *testing.T) {

assert.NotNil(t, svc)

ctx := user.SetContextWithEmail(context.TODO(), "[email protected]")
ctx := user.SetContextWithEmail(context.TODO(), tt.email)
got, err := svc.Create(ctx, tt.user)
if tt.wantErr != nil {
assert.Error(t, err)
Expand Down

0 comments on commit fe57407

Please sign in to comment.