@@ -52,6 +52,8 @@ import {
52
52
setGeneralErrorToLocalStorage ,
53
53
isAccountLinkingSupported ,
54
54
backendBeforeEach ,
55
+ getDefaultSignUpFieldValues ,
56
+ getTestEmail ,
55
57
} from "../helpers" ;
56
58
57
59
describe ( "SuperTokens Email Verification" , function ( ) {
@@ -114,14 +116,11 @@ describe("SuperTokens Email Verification", function () {
114
116
page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
115
117
] ) ;
116
118
await toggleSignInSignUp ( page ) ;
117
- const email = `john.doe${ Date . now ( ) } @supertokens.io` ;
118
- await signUp ( page , [
119
- { name : "email" , value : email } ,
120
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
121
- { name : "name" , value : "John Doe" } ,
122
- { name : "age" , value : "20" } ,
123
- { name : "country" , value : "" } ,
124
- ] ) ;
119
+
120
+ const email = getTestEmail ( ) ;
121
+ const { fieldValues, postValues } = getDefaultSignUpFieldValues ( { email } ) ;
122
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
123
+
125
124
await waitForSTElement ( page , "[data-supertokens~='sendVerifyEmailIcon']" ) ;
126
125
127
126
await fetch ( `${ TEST_APPLICATION_SERVER_BASE_URL } /deleteUser` , {
@@ -169,14 +168,10 @@ describe("SuperTokens Email Verification", function () {
169
168
page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
170
169
] ) ;
171
170
await toggleSignInSignUp ( page ) ;
172
- const email = `john.doe${ Date . now ( ) } @supertokens.io` ;
173
- await signUp ( page , [
174
- { name : "email" , value : email } ,
175
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
176
- { name : "name" , value : "John Doe" } ,
177
- { name : "age" , value : "20" } ,
178
- { name : "country" , value : "" } ,
179
- ] ) ;
171
+ const email = getTestEmail ( ) ;
172
+ const { fieldValues, postValues } = getDefaultSignUpFieldValues ( { email } ) ;
173
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
174
+
180
175
await waitForSTElement ( page , "[data-supertokens~='sendVerifyEmailIcon']" ) ;
181
176
let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
182
177
assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
@@ -264,24 +259,15 @@ describe("SuperTokens Email Verification", function () {
264
259
] ) ;
265
260
} ) ;
266
261
267
- it ( "Should redirect to verify email screen on successful sign up when mode is REQUIRED and email is not verified and then post verification should redirect with original redirectPath and newUser" , async function ( ) {
262
+ it ( "Should redirect to verify email screen on successful sign up when mode is REQUIRED and email is not verified and then post verification should redirect with original redirectPath (w/ leading slash) and newUser" , async function ( ) {
268
263
await Promise . all ( [
269
- page . goto ( `${ TEST_CLIENT_BASE_URL } /auth?redirectToPath=%2Fredirect-here` ) ,
264
+ page . goto ( `${ TEST_CLIENT_BASE_URL } /auth?redirectToPath=%2Fredirect-here%3Ffoo%3Dbar ` ) ,
270
265
page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
271
266
] ) ;
272
267
await toggleSignInSignUp ( page ) ;
273
- const rid = "emailpassword" ;
274
- await signUp (
275
- page ,
276
- [
277
- { name :
"email" , value :
"[email protected] " } ,
278
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
279
- { name : "name" , value : "John Doe" } ,
280
- { name : "age" , value : "20" } ,
281
- ] ,
282
- '{"formFields":[{"id":"email","value":"[email protected] "},{"id":"password","value":"Str0ngP@ssw0rd"},{"id":"name","value":"John Doe"},{"id":"age","value":"20"},{"id":"country","value":""}]}' ,
283
- rid
284
- ) ;
268
+ const { fieldValues
, postValues
} = getDefaultSignUpFieldValues ( { email :
"[email protected] " } ) ;
269
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
270
+
285
271
let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
286
272
assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
287
273
@@ -295,9 +281,36 @@ describe("SuperTokens Email Verification", function () {
295
281
// click on the continue button
296
282
await Promise . all ( [ submitForm ( page ) , page . waitForNavigation ( { waitUntil : "networkidle0" } ) ] ) ;
297
283
298
- // check that we are in /redirect-here
299
- pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
300
- assert . deepStrictEqual ( pathname , "/redirect-here" ) ;
284
+ // check that we are in /redirect-here?foo=bar
285
+ const urlWithQP = await page . evaluate ( ( ) => window . location . pathname + window . location . search ) ;
286
+ assert . deepStrictEqual ( urlWithQP , "/redirect-here?foo=bar" ) ;
287
+ } ) ;
288
+
289
+ it ( "Should redirect to verify email screen on successful sign up when mode is REQUIRED and email is not verified and then post verification should redirect with original redirectPath (w/o leading slash) and newUser" , async function ( ) {
290
+ await Promise . all ( [
291
+ page . goto ( `${ TEST_CLIENT_BASE_URL } /auth?redirectToPath=%3Ffoo%3Dbar` ) ,
292
+ page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
293
+ ] ) ;
294
+ await toggleSignInSignUp ( page ) ;
295
+ const { fieldValues, postValues } = getDefaultSignUpFieldValues ( { email : getTestEmail ( ) } ) ;
296
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
297
+
298
+ let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
299
+ assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
300
+
301
+ // we wait for email to be created
302
+ await new Promise ( ( r ) => setTimeout ( r , 1000 ) ) ;
303
+
304
+ // we fetch the email verification link and go to that
305
+ const latestURLWithToken = await getLatestURLWithToken ( ) ;
306
+ await Promise . all ( [ page . waitForNavigation ( { waitUntil : "networkidle0" } ) , page . goto ( latestURLWithToken ) ] ) ;
307
+
308
+ // click on the continue button
309
+ await Promise . all ( [ submitForm ( page ) , page . waitForNavigation ( { waitUntil : "networkidle0" } ) ] ) ;
310
+
311
+ // check that we are in /?foo=bar
312
+ const urlWithQP = await page . evaluate ( ( ) => window . location . pathname + window . location . search ) ;
313
+ assert . deepStrictEqual ( urlWithQP , "/?foo=bar" ) ;
301
314
} ) ;
302
315
303
316
it ( "Should redirect to verify email screen on successful sign in when mode is REQUIRED and email is not verified" , async function ( ) {
@@ -451,17 +464,8 @@ describe("SuperTokens Email Verification", function () {
451
464
452
465
it ( 'Should show "Email Verification successful" screen when token is valid with an active session' , async function ( ) {
453
466
await toggleSignInSignUp ( page ) ;
454
- await signUp (
455
- page ,
456
- [
457
- { name :
"email" , value :
"[email protected] " } ,
458
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
459
- { name : "name" , value : "John Doe" } ,
460
- { name : "age" , value : "20" } ,
461
- ] ,
462
- '{"formFields":[{"id":"email","value":"[email protected] "},{"id":"password","value":"Str0ngP@ssw0rd"},{"id":"name","value":"John Doe"},{"id":"age","value":"20"},{"id":"country","value":""}]}' ,
463
- "emailpassword"
464
- ) ;
467
+ const { fieldValues
, postValues
} = getDefaultSignUpFieldValues ( { email :
"[email protected] " } ) ;
468
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
465
469
466
470
const latestURLWithToken = await getLatestURLWithToken ( ) ;
467
471
await Promise . all ( [ page . waitForNavigation ( { waitUntil : "networkidle0" } ) , page . goto ( latestURLWithToken ) ] ) ;
@@ -518,17 +522,8 @@ describe("SuperTokens Email Verification", function () {
518
522
] ) ;
519
523
await toggleSignInSignUp ( page ) ;
520
524
521
- await signUp (
522
- page ,
523
- [
524
- { name :
"email" , value :
"[email protected] " } ,
525
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
526
- { name : "name" , value : "John Doe" } ,
527
- { name : "age" , value : "20" } ,
528
- ] ,
529
- '{"formFields":[{"id":"email","value":"[email protected] "},{"id":"password","value":"Str0ngP@ssw0rd"},{"id":"name","value":"John Doe"},{"id":"age","value":"20"},{"id":"country","value":""}]}' ,
530
- "emailpassword"
531
- ) ;
525
+ const { fieldValues
, postValues
} = getDefaultSignUpFieldValues ( { email :
"[email protected] " } ) ;
526
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
532
527
533
528
const latestURLWithToken = await getLatestURLWithToken ( ) ;
534
529
await Promise . all ( [
@@ -708,17 +703,8 @@ describe("SuperTokens Email Verification general errors", function () {
708
703
709
704
it ( 'Should show "General Error" when API returns "GENERAL_ERROR"' , async function ( ) {
710
705
await toggleSignInSignUp ( page ) ;
711
- await signUp (
712
- page ,
713
- [
714
- { name :
"email" , value :
"[email protected] " } ,
715
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
716
- { name : "name" , value : "John Doe" } ,
717
- { name : "age" , value : "20" } ,
718
- ] ,
719
- '{"formFields":[{"id":"email","value":"[email protected] "},{"id":"password","value":"Str0ngP@ssw0rd"},{"id":"name","value":"John Doe"},{"id":"age","value":"20"},{"id":"country","value":""}]}' ,
720
- "emailpassword"
721
- ) ;
706
+ const { fieldValues
, postValues
} = getDefaultSignUpFieldValues ( { email :
"[email protected] " } ) ;
707
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
722
708
723
709
const latestURLWithToken = await getLatestURLWithToken ( ) ;
724
710
await page . goto ( latestURLWithToken ) ;
@@ -903,18 +889,8 @@ describe("Email verification signOut errors", function () {
903
889
await toggleSignInSignUp ( page ) ;
904
890
await page . evaluate ( ( ) => localStorage . setItem ( "SHOW_GENERAL_ERROR" , "SESSION SIGN_OUT" ) ) ;
905
891
906
- const rid = "emailpassword" ;
907
- await signUp (
908
- page ,
909
- [
910
- { name :
"email" , value :
"[email protected] " } ,
911
- { name : "password" , value : "Str0ngP@ssw0rd" } ,
912
- { name : "name" , value : "John Doe" } ,
913
- { name : "age" , value : "20" } ,
914
- ] ,
915
- '{"formFields":[{"id":"email","value":"[email protected] "},{"id":"password","value":"Str0ngP@ssw0rd"},{"id":"name","value":"John Doe"},{"id":"age","value":"20"},{"id":"country","value":""}]}' ,
916
- rid
917
- ) ;
892
+ const { fieldValues
, postValues
} = getDefaultSignUpFieldValues ( { email :
"[email protected] " } ) ;
893
+ await signUp ( page , fieldValues , postValues , "emailpassword" ) ;
918
894
919
895
let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
920
896
assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
0 commit comments