Skip to content

Commit

Permalink
add test for VerifyAndChangeEmailLink
Browse files Browse the repository at this point in the history
  • Loading branch information
tyahha committed May 20, 2022
1 parent 2c5dd06 commit 57b9ee1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions auth/email_action_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
testActionLink = "https://test.link"
testActionLinkFormat = `{"oobLink": %q}`
testEmail = "user@domain.com"
testNewEmail = "user-new@domain.com"
)

var testActionLinkResponse = []byte(fmt.Sprintf(testActionLinkFormat, testActionLink))
Expand Down Expand Up @@ -309,6 +310,55 @@ func TestEmailVerificationLinkError(t *testing.T) {
}
}

func TestVerifyAndChangeEmailLink(t *testing.T) {
s := echoServer(testActionLinkResponse, t)
defer s.Close()

link, err := s.Client.VerifyAndChangeEmailLink(context.Background(), testEmail, testNewEmail)
if err != nil {
t.Fatal(err)
}
if link != testActionLink {
t.Errorf("TestVerifyAndChangeEmailLink() = %q; want = %q", link, testActionLink)
}

want := map[string]interface{}{
"requestType": "VERIFY_AND_CHANGE_EMAIL",
"email": testEmail,
"returnOobLink": true,
"newEmail": testNewEmail,
}
if err := checkActionLinkRequest(want, s); err != nil {
t.Fatalf("TestVerifyAndChangeEmailLink() %v", err)
}
}

func TestVerifyAndChangeEmailLinkWithSettings(t *testing.T) {
s := echoServer(testActionLinkResponse, t)
defer s.Close()

link, err := s.Client.VerifyAndChangeEmailLinkWithSettings(context.Background(), testEmail, testNewEmail, testActionCodeSettings)
if err != nil {
t.Fatal(err)
}
if link != testActionLink {
t.Errorf("VerifyAndChangeEmailLinkWithSettings() = %q; want = %q", link, testActionLink)
}

want := map[string]interface{}{
"requestType": "VERIFY_AND_CHANGE_EMAIL",
"email": testEmail,
"returnOobLink": true,
"newEmail": testNewEmail,
}
for k, v := range testActionCodeSettingsMap {
want[k] = v
}
if err := checkActionLinkRequest(want, s); err != nil {
t.Fatalf("VerifyAndChangeEmailLinkWithSettings() %v", err)
}
}

func checkActionLinkRequest(want map[string]interface{}, s *mockAuthServer) error {
wantURL := "/projects/mock-project-id/accounts:sendOobCode"
return checkActionLinkRequestWithURL(want, wantURL, s)
Expand Down

0 comments on commit 57b9ee1

Please sign in to comment.