Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed Jun 14, 2024
1 parent 396688e commit 45ca958
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions core/group/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
testOrgID = uuid.NewString()
testGroupID = uuid.NewString()
testUserID = uuid.NewString()
testRoleID = uuid.NewString()
testGroupSlug = "test-group-slug"
testGroup = group.Group{
ID: testGroupID,
Expand Down Expand Up @@ -424,3 +425,51 @@ func TestService_Create(t *testing.T) {
})
}
}

func TestService_ListUserGroup(t *testing.T) {
t.Parallel()

tests := []struct {
name string
userId string
roleId string
setup func(t *testing.T) *group.Service
want []group.Group
wantErr error
}{
{
name: "ListUserGroup",
userId: testUserID,
roleId: testRoleID,
setup: func(t *testing.T) *group.Service {
t.Helper()
repository := &mocks.Repository{}
cachedRepository := &mocks.CachedRepository{}
relationService := &mocks.RelationService{}
userService := &mocks.UserService{}
activityService := &mocks.ActivityService{}
repository.EXPECT().ListUserGroups(mock.Anything, testUserID, testRoleID).Return([]group.Group{testGroup}, nil)
return group.NewService(testLogger, repository, cachedRepository, relationService, userService, activityService)
},
want: []group.Group{testGroup},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
svc := tt.setup(t)

assert.NotNil(t, svc)

got, err := svc.ListUserGroups(context.TODO(), tt.userId, tt.roleId)
if tt.wantErr != nil {
assert.Error(t, err)
assert.True(t, errors.Is(err, tt.wantErr))
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 45ca958

Please sign in to comment.