Skip to content

Commit

Permalink
feat: remove unnecessary bool return from new functions (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Tran <[email protected]>
  • Loading branch information
tdeshong and ctran88 authored Nov 22, 2024
1 parent f0e7239 commit be26032
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
39 changes: 18 additions & 21 deletions app_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,22 @@ func (a *appUser) Update(userID string, updateBody UpdateBody) (*PassageUser, er
}

// Delete deletes a user by their user string
// returns true on success, false and error on failure (bool, err)
func (a *appUser) Delete(userID string) (bool, error) {
ok, err := a.app.DeleteUser(userID)
if err != nil {
// returns error on failure
func (a *appUser) Delete(userID string) error {
if _, err := a.app.DeleteUser(userID); err != nil {
var e Error
if errors.As(err, &e) {
return ok, PassageError{
return PassageError{
Message: e.Message,
StatusCode: e.StatusCode,
ErrorCode: e.ErrorCode,
}
}

return ok, err
return err
}

return ok, nil
return nil
}

// Create receives a CreateUserBody struct, creating a user with provided values
Expand Down Expand Up @@ -176,41 +175,39 @@ func (a *appUser) ListDevices(userID string) ([]WebAuthnDevices, error) {
}

// RevokeDevice gets a user using their userID
// returns a true success, error on failure
func (a *appUser) RevokeDevice(userID, deviceID string) (bool, error) {
ok, err := a.app.RevokeUserDevice(userID, deviceID)
if err != nil {
// returns error on failure
func (a *appUser) RevokeDevice(userID, deviceID string) error {
if _, err := a.app.RevokeUserDevice(userID, deviceID); err != nil {
var e Error
if errors.As(err, &e) {
return ok, PassageError{
return PassageError{
Message: e.Message,
StatusCode: e.StatusCode,
ErrorCode: e.ErrorCode,
}
}

return ok, err
return err
}

return ok, nil
return nil
}

// RevokeRefreshTokens revokes a users refresh tokens
// returns true on success, error on failure
func (a *appUser) RevokeRefreshTokens(userID string) (bool, error) {
ok, err := a.app.SignOut(userID)
if err != nil {
// returns error on failure
func (a *appUser) RevokeRefreshTokens(userID string) error {
if _, err := a.app.SignOut(userID); err != nil {
var e Error
if errors.As(err, &e) {
return ok, PassageError{
return PassageError{
Message: e.Message,
StatusCode: e.StatusCode,
ErrorCode: e.ErrorCode,
}
}

return ok, err
return err
}

return ok, nil
return nil
}
14 changes: 6 additions & 8 deletions app_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,8 @@ func TestDelete(t *testing.T) {
})
require.Nil(t, err)

result, err := psg.User.Delete(CreatedUser.ID)
err = psg.User.Delete(CreatedUser.ID)
require.Nil(t, err)
assert.Equal(t, result, true)
})

t.Run("Error: unauthorized", func(t *testing.T) {
Expand All @@ -405,7 +404,7 @@ func TestDelete(t *testing.T) {
})
require.Nil(t, err)

_, err = psg.User.Delete(CreatedUser.ID)
err = psg.User.Delete(CreatedUser.ID)
require.NotNil(t, err)
passageUnauthorizedAsserts(t, err)
})
Expand All @@ -416,7 +415,7 @@ func TestDelete(t *testing.T) {
})
require.Nil(t, err)

_, err = psg.User.Delete("PassageUserID")
err = psg.User.Delete("PassageUserID")
require.NotNil(t, err)

passageUserNotFoundAsserts(t, err)
Expand Down Expand Up @@ -468,9 +467,8 @@ func TestRevokeRefreshTokens(t *testing.T) {
})
require.Nil(t, err)

result, err := psg.User.RevokeRefreshTokens(PassageUserID)
err = psg.User.RevokeRefreshTokens(PassageUserID)
require.Nil(t, err)
assert.Equal(t, result, true)
})

t.Run("Error: unauthorized", func(t *testing.T) {
Expand All @@ -479,7 +477,7 @@ func TestRevokeRefreshTokens(t *testing.T) {
})
require.Nil(t, err)

_, err = psg.User.RevokeRefreshTokens(PassageUserID)
err = psg.User.RevokeRefreshTokens(PassageUserID)
require.NotNil(t, err)
passageUnauthorizedAsserts(t, err)
})
Expand All @@ -490,7 +488,7 @@ func TestRevokeRefreshTokens(t *testing.T) {
})
require.Nil(t, err)

_, err = psg.User.RevokeRefreshTokens("PassageUserID")
err = psg.User.RevokeRefreshTokens("PassageUserID")
require.NotNil(t, err)

passageUserNotFoundAsserts(t, err)
Expand Down

0 comments on commit be26032

Please sign in to comment.