Skip to content

Commit

Permalink
fix(account): improve error handling in user credential retrieval and…
Browse files Browse the repository at this point in the history
… update tests for asset publishing

- Updated error handling in GetUserByCredentials to correctly check for not found errors.
- Enhanced test cases in pubsub_test.go to assert no errors during asset event publishing, improving test reliability.
- Added comments to clarify intent in test cases, ensuring better maintainability and understanding of the codebase.
  • Loading branch information
kasugamirai committed Jan 7, 2025
1 parent 7353e6b commit 51af443
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion account/accountusecase/accountinteractor/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (i *User) SearchUser(ctx context.Context, keyword string) (user.SimpleList,
func (i *User) GetUserByCredentials(ctx context.Context, inp accountinterfaces.GetUserByCredentials) (u *user.User, err error) {
return Run1(ctx, nil, i.repos, Usecase().Transaction(), func(ctx context.Context) (*user.User, error) {
u, err = i.repos.User.FindByNameOrEmail(ctx, inp.Email)
if err != nil && !errors.Is(rerror.ErrNotFound, err) {
if err != nil && !errors.Is(err, rerror.ErrNotFound) {
return nil, err
} else if u == nil {
return nil, accountinterfaces.ErrInvalidUserEmail
Expand Down
1 change: 1 addition & 0 deletions asset/domain/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func TestBuilder_MustBuild(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
if tt.wantPanic != nil {
assert.PanicsWithValue(t, tt.wantPanic, func() {
//nolint:errcheck // MustBuild panics on error, return value is intentionally not checked
tt.build().MustBuild()
})
} else {
Expand Down
14 changes: 7 additions & 7 deletions asset/infrastructure/pubsub/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func TestAssetPubSub_Subscribe(t *testing.T) {

// Publish events
ctx := context.Background()
ps.PublishAssetCreated(ctx, asset)
ps.PublishAssetUpdated(ctx, asset)
ps.PublishAssetUploaded(ctx, asset)
assert.NoError(t, ps.PublishAssetCreated(ctx, asset))
assert.NoError(t, ps.PublishAssetUpdated(ctx, asset))
assert.NoError(t, ps.PublishAssetUploaded(ctx, asset))

// Check received events
mu.Lock()
Expand Down Expand Up @@ -94,9 +94,9 @@ func TestAssetPubSub_SubscribeSpecificEvent(t *testing.T) {

// Publish different events
ctx := context.Background()
ps.PublishAssetCreated(ctx, asset) // Should be received
ps.PublishAssetUpdated(ctx, asset) // Should be ignored
ps.PublishAssetUploaded(ctx, asset) // Should be ignored
assert.NoError(t, ps.PublishAssetCreated(ctx, asset)) // Should be received
assert.NoError(t, ps.PublishAssetUpdated(ctx, asset)) // Should be ignored
assert.NoError(t, ps.PublishAssetUploaded(ctx, asset)) // Should be ignored

// Check received events
mu.Lock()
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestAssetPubSub_Unsubscribe(t *testing.T) {

// Publish event
ctx := context.Background()
ps.PublishAssetCreated(ctx, asset)
assert.NoError(t, ps.PublishAssetCreated(ctx, asset))

// Check no events were received
mu.Lock()
Expand Down

0 comments on commit 51af443

Please sign in to comment.