Repository: firebase/firebase-admin-go
Pull request #425 (2021-03-24 20:42:19)

feat(auth): GetUserByProviderID -> GetUserByProviderUID
Fix incorrect method name. The old one has been left as a (deprecated) alias.


Patch:
diff --git a/auth/user_mgt.go b/auth/user_mgt.go
index e4ada62..c44e15a 100644
--- a/auth/user_mgt.go
+++ b/auth/user_mgt.go
@@ -609,15 +609,22 @@ func (c *baseClient) GetUserByPhoneNumber(ctx context.Context, phone string) (*U
 	})
 }
 
-// GetUserByProviderID gets the user data for the user corresponding to a given provider ID.
+// GetUserByProviderID is an alias for GetUserByProviderUID.
+//
+// Deprecated. Use GetUserByProviderUID instead.
+func (c *baseClient) GetUserByProviderID(ctx context.Context, providerID string, providerUID string) (*UserRecord, error) {
+	return c.GetUserByProviderUID(ctx, providerID, providerUID)
+}
+
+// GetUserByProviderUID gets the user data for the user corresponding to a given provider ID.
 //
 // See
-// [Retrieve user data](https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data)
+// https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
 // for code samples and detailed documentation.
 //
 // `providerID` indicates the provider, such as 'google.com' for the Google provider.
 // `providerUID` is the user identifier for the given provider.
-func (c *baseClient) GetUserByProviderID(ctx context.Context, providerID string, providerUID string) (*UserRecord, error) {
+func (c *baseClient) GetUserByProviderUID(ctx context.Context, providerID string, providerUID string) (*UserRecord, error) {
 	// Although we don't really advertise it, we want to also handle non-federated
 	// IDPs with this call. So if we detect one of them, we'll reroute this
 	// request appropriately.


Test patch:
diff --git a/auth/user_mgt_test.go b/auth/user_mgt_test.go
index 32b2e72..78ad58d 100644
--- a/auth/user_mgt_test.go
+++ b/auth/user_mgt_test.go
@@ -146,10 +146,10 @@ func TestGetUserByProviderIDNotFound(t *testing.T) {
 	s := echoServer(mockUsers, t)
 	defer s.Close()
 
-	userRecord, err := s.Client.GetUserByProviderID(context.Background(), "google.com", "google_uid1")
+	userRecord, err := s.Client.GetUserByProviderUID(context.Background(), "google.com", "google_uid1")
 	want := "cannot find user from providerID: { google.com, google_uid1 }"
 	if userRecord != nil || err == nil || err.Error() != want || !IsUserNotFound(err) {
-		t.Errorf("GetUserByProviderID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
+		t.Errorf("GetUserByProviderUID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
 	}
 }
 
@@ -182,19 +182,19 @@ func TestGetUserByProviderId(t *testing.T) {
 	for _, tc := range cases {
 		t.Run(tc.providerID+":"+tc.providerUID, func(t *testing.T) {
 
-			_, err := s.Client.GetUserByProviderID(context.Background(), tc.providerID, tc.providerUID)
+			_, err := s.Client.GetUserByProviderUID(context.Background(), tc.providerID, tc.providerUID)
 			if err != nil {
-				t.Fatalf("GetUserByProviderID() = %q", err)
+				t.Fatalf("GetUserByProviderUID() = %q", err)
 			}
 
 			got := string(s.Rbody)
 			if got != tc.want {
-				t.Errorf("GetUserByProviderID() Req = %v; want = %v", got, tc.want)
+				t.Errorf("GetUserByProviderUID() Req = %v; want = %v", got, tc.want)
 			}
 
 			wantPath := "/projects/mock-project-id/accounts:lookup"
 			if s.Req[0].RequestURI != wantPath {
-				t.Errorf("GetUserByProviderID() URL = %q; want = %q", s.Req[0].RequestURI, wantPath)
+				t.Errorf("GetUserByProviderUID() URL = %q; want = %q", s.Req[0].RequestURI, wantPath)
 			}
 		})
 	}
@@ -220,16 +220,16 @@ func TestInvalidGetUser(t *testing.T) {
 		t.Errorf("GetUserPhoneNumber('') = (%v, %v); want = (nil, error)", user, err)
 	}
 
-	userRecord, err := client.GetUserByProviderID(context.Background(), "", "google_uid1")
+	userRecord, err := client.GetUserByProviderUID(context.Background(), "", "google_uid1")
 	want := "providerID must be a non-empty string"
 	if userRecord != nil || err == nil || err.Error() != want {
-		t.Errorf("GetUserByProviderID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
+		t.Errorf("GetUserByProviderUID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
 	}
 
-	userRecord, err = client.GetUserByProviderID(context.Background(), "google.com", "")
+	userRecord, err = client.GetUserByProviderUID(context.Background(), "google.com", "")
 	want = "providerUID must be a non-empty string"
 	if userRecord != nil || err == nil || err.Error() != want {
-		t.Errorf("GetUserByProviderID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
+		t.Errorf("GetUserByProviderUID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
 	}
 }
 
diff --git a/integration/auth/user_mgt_test.go b/integration/auth/user_mgt_test.go
index 13a27dd..c32f6d3 100644
--- a/integration/auth/user_mgt_test.go
+++ b/integration/auth/user_mgt_test.go
@@ -80,7 +80,7 @@ func TestGetUser(t *testing.T) {
 	}
 }
 
-func TestGetUserByProviderID(t *testing.T) {
+func TestGetUserByProviderUID(t *testing.T) {
 	// TODO(rsgowman): Once we can link a provider id with a user, just do that
 	// here instead of importing a new user.
 	importUserUID := randomUID()
@@ -98,13 +98,13 @@ func TestGetUserByProviderID(t *testing.T) {
 	importUser(t, importUserUID, userToImport)
 	defer deleteUser(importUserUID)
 
-	userRecord, err := client.GetUserByProviderID(context.Background(), "google.com", providerUID)
+	userRecord, err := client.GetUserByProviderUID(context.Background(), "google.com", providerUID)
 	if err != nil {
-		t.Fatalf("GetUserByProviderID() = %q", err)
+		t.Fatalf("GetUserByProviderUID() = %q", err)
 	}
 
 	if userRecord.UID != importUserUID {
-		t.Errorf("GetUserByProviderID().UID = %v; want = %v", userRecord.UID, importUserUID)
+		t.Errorf("GetUserByProviderUID().UID = %v; want = %v", userRecord.UID, importUserUID)
 	}
 }
 
@@ -124,7 +124,7 @@ func TestGetNonExistingUser(t *testing.T) {
 		t.Errorf("GetUser(non.existing) = (%v, %v); want = (nil, error)", user, err)
 	}
 
-	user, err = client.GetUserByProviderID(context.Background(), "google.com", "a-uid-that-doesnt-exist")
+	user, err = client.GetUserByProviderUID(context.Background(), "google.com", "a-uid-that-doesnt-exist")
 	if user != nil || !auth.IsUserNotFound(err) {
 		t.Errorf("GetUser(non.existing) = (%v, %v); want = (nil, error)", user, err)
 	}