Skip to content

Commit f4e3edb

Browse files
authored
Handling USER_NOT_FOUND errors in UpdateUser() and DeleteUser() (#150)
* Adding new integration tests to auth/user-mgt code * Updated changelog
1 parent 27160ef commit f4e3edb

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Unreleased
22

3+
- [fixed] `auth.UpdateUser()` and `auth.DeleteUser()` return the expected
4+
`UserNotFound` error when called with a non-existing uid.
35
- [added] Implemented the `auth.ImportUsers()` function for importing
46
users into Firebase Auth in bulk.
57

68
# v3.0.0
79

8-
- All functions that make network calls now take context as an argument.
10+
- [changed] All functions that make network calls now take context as an argument.
911

1012
# v2.7.0
1113

auth/user_mgt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ var serverError = map[string]string{
824824
"INSUFFICIENT_PERMISSION": insufficientPermission,
825825
"PHONE_NUMBER_EXISTS": phoneNumberAlreadyExists,
826826
"PROJECT_NOT_FOUND": projectNotFound,
827+
"USER_NOT_FOUND": userNotFound,
827828
}
828829

829830
func handleServerError(err error) error {

integration/auth/user_mgt_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,33 @@ func TestUserManagement(t *testing.T) {
6969
}
7070
}
7171

72+
func TestGetNonExistingUser(t *testing.T) {
73+
user, err := client.GetUser(context.Background(), "non.existing")
74+
if user != nil || !auth.IsUserNotFound(err) {
75+
t.Errorf("GetUser(non.existing) = (%v, %v); want = (nil, error)", user, err)
76+
}
77+
78+
user, err = client.GetUserByEmail(context.Background(), "[email protected]")
79+
if user != nil || !auth.IsUserNotFound(err) {
80+
t.Errorf("GetUserByEmail(non.existing) = (%v, %v); want = (nil, error)", user, err)
81+
}
82+
}
83+
84+
func TestUpdateNonExistingUser(t *testing.T) {
85+
update := (&auth.UserToUpdate{}).Email("[email protected]")
86+
user, err := client.UpdateUser(context.Background(), "non.existing", update)
87+
if user != nil || !auth.IsUserNotFound(err) {
88+
t.Errorf("UpdateUser(non.existing) = (%v, %v); want = (nil, error)", user, err)
89+
}
90+
}
91+
92+
func TestDeleteNonExistingUser(t *testing.T) {
93+
err := client.DeleteUser(context.Background(), "non.existing")
94+
if !auth.IsUserNotFound(err) {
95+
t.Errorf("DeleteUser(non.existing) = %v; want = error", err)
96+
}
97+
}
98+
7299
// N.B if the tests are failing due to inability to create existing users, manual
73100
// cleanup of the previus test run might be required, delete the unwanted users via:
74101
// https://console.firebase.google.com/u/0/project/<project-id>/authentication/users

0 commit comments

Comments
 (0)