forked from raystack/frontier
-
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.
- Loading branch information
1 parent
448fb15
commit 84c46a7
Showing
1 changed file
with
61 additions
and
0 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 |
---|---|---|
|
@@ -322,3 +322,64 @@ func TestService_GetByID(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestService_FetchCurrentUser(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
email string | ||
setup func(t *testing.T) *user.Service | ||
urn string | ||
want user.User | ||
wantErr error | ||
}{ | ||
{ | ||
name: "FetchCurrentUser", | ||
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, "[email protected]"). | ||
Return(user.User{ | ||
ID: "qwer-1234-tyui-5678-opas-90", | ||
Name: "John Doe", | ||
Email: "[email protected]"}, nil).Once() | ||
|
||
activityService.EXPECT(). | ||
Log(mock.Anything, user.AuditKeyUserUpdate, "", user.UserLogData{Entity: "user", Name: "John Doe", Email: "[email protected]"}).Return(nil).Once() | ||
return user.NewService(logger, repository, activityService) | ||
}, | ||
want: user.User{ | ||
ID: "qwer-1234-tyui-5678-opas-90", | ||
Name: "John Doe", | ||
Email: "[email protected]", | ||
}, | ||
wantErr: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
svc := tt.setup(t) | ||
|
||
assert.NotNil(t, svc) | ||
|
||
ctx := user.SetContextWithEmail(context.Background(), tt.email) | ||
|
||
got, err := svc.FetchCurrentUser(ctx) | ||
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) | ||
}) | ||
} | ||
} |