Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove unnecessary bool return from new functions #110

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading