33 * All rights reserved.
44 */
55
6- import fetch from "isomorphic-fetch" ;
7- import { TEST_SERVER_BASE_URL , TEST_CLIENT_BASE_URL } from "../constants" ;
6+ import { TEST_CLIENT_BASE_URL } from "../constants" ;
87import {
9- backendBeforeEach ,
108 setupBrowser ,
119 screenshotOnFailure ,
1210 clearBrowserCookiesWithoutAffectingConsole ,
1311 toggleSignInSignUp ,
1412 getTestEmail ,
1513 waitForSTElement ,
1614 submitForm ,
17- setEnabledRecipes ,
1815 setInputValues ,
19- setAccountLinkingConfig ,
2016 getPasswordlessDevice ,
2117 waitForUrl ,
2218 changeEmail ,
2319 getLatestURLWithToken ,
2420 getUserIdWithFetch ,
2521 submitFormUnsafe ,
22+ backendHook ,
23+ setupCoreApp ,
24+ setupST ,
25+ isWebauthnSupported ,
2626} from "../helpers" ;
2727import {
2828 openRecoveryAccountPage ,
@@ -45,25 +45,21 @@ describe("SuperTokens WebAuthn Account Linking", function () {
4545 let browser ;
4646 let page ;
4747 let consoleLogs = [ ] ;
48+ let skipped = false ;
49+ const appConfig = {
50+ enabledRecipes : [ "webauthn" , "emailpassword" , "session" , "dashboard" , "userroles" , "multifactorauth" ] ,
51+ } ;
4852
4953 before ( async function ( ) {
50- await backendBeforeEach ( ) ;
51-
52- await fetch ( `${ TEST_SERVER_BASE_URL } /startst` , {
53- method : "POST" ,
54- } ) . catch ( console . error ) ;
55-
56- await setEnabledRecipes ( [
57- "webauthn" ,
58- "emailpassword" ,
59- "passwordless" ,
60- "emailverification" ,
61- "session" ,
62- "dashboard" ,
63- "userroles" ,
64- "multifactorauth" ,
65- "accountlinking" ,
66- ] ) ;
54+ if ( ! ( await isWebauthnSupported ( ) ) ) {
55+ skipped = true ;
56+ this . skip ( ) ;
57+ }
58+
59+ await backendHook ( "before" ) ;
60+ const coreUrl = await setupCoreApp ( ) ;
61+ appConfig . coreUrl = coreUrl ;
62+ await setupST ( appConfig ) ;
6763
6864 browser = await setupBrowser ( ) ;
6965 page = await browser . newPage ( ) ;
@@ -76,29 +72,39 @@ describe("SuperTokens WebAuthn Account Linking", function () {
7672 } ) ;
7773
7874 after ( async function ( ) {
79- await browser . close ( ) ;
80- await fetch ( `${ TEST_SERVER_BASE_URL } /after` , {
81- method : "POST" ,
82- } ) . catch ( console . error ) ;
83-
84- await fetch ( `${ TEST_SERVER_BASE_URL } /stopst` , {
85- method : "POST" ,
86- } ) . catch ( console . error ) ;
75+ if ( skipped ) {
76+ return ;
77+ }
78+
79+ await page ?. close ( ) ;
80+ await browser ?. close ( ) ;
81+ await backendHook ( "after" ) ;
8782 } ) ;
8883
89- afterEach ( function ( ) {
90- return screenshotOnFailure ( this , browser ) ;
84+ afterEach ( async function ( ) {
85+ await screenshotOnFailure ( this , browser ) ;
86+ await backendHook ( "afterEach" ) ;
9187 } ) ;
9288
9389 beforeEach ( async function ( ) {
90+ await backendHook ( "beforeEach" ) ;
9491 consoleLogs = [ ] ;
9592 consoleLogs = await clearBrowserCookiesWithoutAffectingConsole ( page , consoleLogs ) ;
9693 await toggleSignInSignUp ( page ) ;
9794 } ) ;
9895
9996 it ( "Should create separate users when signing up with same email using different auth methods (account linking disabled)" , async function ( ) {
10097 // Disable account linking
101- await setAccountLinkingConfig ( false , false ) ;
98+ await setupST ( {
99+ ...appConfig ,
100+ accountLinkingConfig : {
101+ enabled : true ,
102+ shouldAutoLink : {
103+ shouldAutomaticallyLink : false ,
104+ shouldRequireVerification : false ,
105+ } ,
106+ } ,
107+ } ) ;
102108 const email = await getTestEmail ( ) ;
103109
104110 await Promise . all ( [
@@ -148,7 +154,16 @@ describe("SuperTokens WebAuthn Account Linking", function () {
148154
149155 it ( "should handle email updates correctly for user that signed up with webauthn" , async ( ) => {
150156 await page . evaluate ( ( ) => window . localStorage . setItem ( "mode" , "REQUIRED" ) ) ;
151- await setAccountLinkingConfig ( false , false ) ;
157+ await setupST ( {
158+ ...appConfig ,
159+ accountLinkingConfig : {
160+ enabled : true ,
161+ shouldAutoLink : {
162+ shouldAutomaticallyLink : false ,
163+ shouldRequireVerification : false ,
164+ } ,
165+ } ,
166+ } ) ;
152167 const email = await getTestEmail ( ) ;
153168
154169 await tryWebauthnSignUp ( page , email ) ;
@@ -197,7 +212,16 @@ describe("SuperTokens WebAuthn Account Linking", function () {
197212
198213 it ( "should allow same emails to be linked but requiring verification" , async ( ) => {
199214 await page . evaluate ( ( ) => window . localStorage . setItem ( "mode" , "REQUIRED" ) ) ;
200- await setAccountLinkingConfig ( true , true , true ) ;
215+ await setupST ( {
216+ ...appConfig ,
217+ accountLinkingConfig : {
218+ enabled : true ,
219+ shouldAutoLink : {
220+ shouldAutomaticallyLink : true ,
221+ shouldRequireVerification : true ,
222+ } ,
223+ } ,
224+ } ) ;
201225 const email = await getTestEmail ( ) ;
202226
203227 await tryPasswordlessSignInUp ( page , email ) ;
0 commit comments