Skip to content

Commit 57b9ee1

Browse files
committed
add test for VerifyAndChangeEmailLink
1 parent 2c5dd06 commit 57b9ee1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

auth/email_action_links_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
testActionLink = "https://test.link"
3030
testActionLinkFormat = `{"oobLink": %q}`
3131
testEmail = "[email protected]"
32+
testNewEmail = "[email protected]"
3233
)
3334

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

313+
func TestVerifyAndChangeEmailLink(t *testing.T) {
314+
s := echoServer(testActionLinkResponse, t)
315+
defer s.Close()
316+
317+
link, err := s.Client.VerifyAndChangeEmailLink(context.Background(), testEmail, testNewEmail)
318+
if err != nil {
319+
t.Fatal(err)
320+
}
321+
if link != testActionLink {
322+
t.Errorf("TestVerifyAndChangeEmailLink() = %q; want = %q", link, testActionLink)
323+
}
324+
325+
want := map[string]interface{}{
326+
"requestType": "VERIFY_AND_CHANGE_EMAIL",
327+
"email": testEmail,
328+
"returnOobLink": true,
329+
"newEmail": testNewEmail,
330+
}
331+
if err := checkActionLinkRequest(want, s); err != nil {
332+
t.Fatalf("TestVerifyAndChangeEmailLink() %v", err)
333+
}
334+
}
335+
336+
func TestVerifyAndChangeEmailLinkWithSettings(t *testing.T) {
337+
s := echoServer(testActionLinkResponse, t)
338+
defer s.Close()
339+
340+
link, err := s.Client.VerifyAndChangeEmailLinkWithSettings(context.Background(), testEmail, testNewEmail, testActionCodeSettings)
341+
if err != nil {
342+
t.Fatal(err)
343+
}
344+
if link != testActionLink {
345+
t.Errorf("VerifyAndChangeEmailLinkWithSettings() = %q; want = %q", link, testActionLink)
346+
}
347+
348+
want := map[string]interface{}{
349+
"requestType": "VERIFY_AND_CHANGE_EMAIL",
350+
"email": testEmail,
351+
"returnOobLink": true,
352+
"newEmail": testNewEmail,
353+
}
354+
for k, v := range testActionCodeSettingsMap {
355+
want[k] = v
356+
}
357+
if err := checkActionLinkRequest(want, s); err != nil {
358+
t.Fatalf("VerifyAndChangeEmailLinkWithSettings() %v", err)
359+
}
360+
}
361+
312362
func checkActionLinkRequest(want map[string]interface{}, s *mockAuthServer) error {
313363
wantURL := "/projects/mock-project-id/accounts:sendOobCode"
314364
return checkActionLinkRequestWithURL(want, wantURL, s)

0 commit comments

Comments
 (0)