Skip to content

Commit

Permalink
Return BadRequestError if user_id is empty (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalef authored Nov 4, 2023
1 parent 88d7882 commit 89b5f46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/store/postgres/userstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (dao *UserStoreDAO) Create(
ctx context.Context,
user *models.CreateUserRequest,
) (*models.User, error) {
if user.UserID == "" {
return nil, models.NewBadRequestError("UserID cannot be empty")
}
userDB := &UserSchema{
UserID: user.UserID,
Email: user.Email,
Expand Down
9 changes: 9 additions & 0 deletions pkg/store/postgres/userstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func TestUserStoreDAO(t *testing.T) {
assert.NotEmpty(t, createdUser.ID)
})

// Test Create
t.Run("Create with no user_id", func(t *testing.T) {
userNoId := &models.CreateUserRequest{
UserID: "",
}
_, err := userStore.Create(ctx, userNoId)
assert.ErrorIs(t, err, models.ErrBadRequest)
})

// Test Get
t.Run("Get", func(t *testing.T) {
retrievedUser, err := userStore.Get(ctx, user.UserID)
Expand Down

0 comments on commit 89b5f46

Please sign in to comment.