@@ -52,6 +52,8 @@ import {
5252 setGeneralErrorToLocalStorage ,
5353 isAccountLinkingSupported ,
5454 backendBeforeEach ,
55+ getDefaultSignUpFieldValues ,
56+ getTestEmail ,
5557} from "../helpers" ;
5658
5759describe ( "SuperTokens Email Verification" , function ( ) {
@@ -114,14 +116,11 @@ describe("SuperTokens Email Verification", function () {
114116 page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
115117 ] ) ;
116118 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+
125124 await waitForSTElement ( page , "[data-supertokens~='sendVerifyEmailIcon']" ) ;
126125
127126 await fetch ( `${ TEST_APPLICATION_SERVER_BASE_URL } /deleteUser` , {
@@ -169,14 +168,10 @@ describe("SuperTokens Email Verification", function () {
169168 page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
170169 ] ) ;
171170 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+
180175 await waitForSTElement ( page , "[data-supertokens~='sendVerifyEmailIcon']" ) ;
181176 let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
182177 assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
@@ -264,24 +259,15 @@ describe("SuperTokens Email Verification", function () {
264259 ] ) ;
265260 } ) ;
266261
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 ( ) {
268263 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 ` ) ,
270265 page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
271266 ] ) ;
272267 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+
285271 let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
286272 assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
287273
@@ -295,9 +281,36 @@ describe("SuperTokens Email Verification", function () {
295281 // click on the continue button
296282 await Promise . all ( [ submitForm ( page ) , page . waitForNavigation ( { waitUntil : "networkidle0" } ) ] ) ;
297283
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" ) ;
301314 } ) ;
302315
303316 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 () {
451464
452465 it ( 'Should show "Email Verification successful" screen when token is valid with an active session' , async function ( ) {
453466 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" ) ;
465469
466470 const latestURLWithToken = await getLatestURLWithToken ( ) ;
467471 await Promise . all ( [ page . waitForNavigation ( { waitUntil : "networkidle0" } ) , page . goto ( latestURLWithToken ) ] ) ;
@@ -518,17 +522,8 @@ describe("SuperTokens Email Verification", function () {
518522 ] ) ;
519523 await toggleSignInSignUp ( page ) ;
520524
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" ) ;
532527
533528 const latestURLWithToken = await getLatestURLWithToken ( ) ;
534529 await Promise . all ( [
@@ -708,17 +703,8 @@ describe("SuperTokens Email Verification general errors", function () {
708703
709704 it ( 'Should show "General Error" when API returns "GENERAL_ERROR"' , async function ( ) {
710705 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" ) ;
722708
723709 const latestURLWithToken = await getLatestURLWithToken ( ) ;
724710 await page . goto ( latestURLWithToken ) ;
@@ -903,18 +889,8 @@ describe("Email verification signOut errors", function () {
903889 await toggleSignInSignUp ( page ) ;
904890 await page . evaluate ( ( ) => localStorage . setItem ( "SHOW_GENERAL_ERROR" , "SESSION SIGN_OUT" ) ) ;
905891
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" ) ;
918894
919895 let pathname = await page . evaluate ( ( ) => window . location . pathname ) ;
920896 assert . deepStrictEqual ( pathname , "/auth/verify-email" ) ;
0 commit comments