3
3
const request = require ( '../lib/request' ) ;
4
4
const fs = require ( 'fs' ) . promises ;
5
5
const Utils = require ( '../lib/Utils' ) ;
6
- const { PublicAPIRouter, pages } = require ( '../lib/Routers/PublicAPIRouter' ) ;
6
+ const { PublicAPIRouter, pages, pageParams } = require ( '../lib/Routers/PublicAPIRouter' ) ;
7
7
8
8
describe ( 'public API' , ( ) => {
9
9
describe ( 'basic request' , ( ) => {
@@ -328,7 +328,7 @@ describe('public API', () => {
328
328
}
329
329
} ) ;
330
330
331
- it ( 'responds to POST request with redirect response (e2e test) ' , async ( ) => {
331
+ it ( 'responds to POST request with redirect response' , async ( ) => {
332
332
await reconfigureServer ( config ) ;
333
333
const response = await request ( {
334
334
url :
@@ -342,7 +342,7 @@ describe('public API', () => {
342
342
) ;
343
343
} ) ;
344
344
345
- it ( 'responds to GET request with content response (e2e test) ' , async ( ) => {
345
+ it ( 'responds to GET request with content response' , async ( ) => {
346
346
await reconfigureServer ( config ) ;
347
347
const response = await request ( {
348
348
url :
@@ -353,6 +353,61 @@ describe('public API', () => {
353
353
expect ( response . status ) . toEqual ( 200 ) ;
354
354
expect ( response . text ) . toContain ( '<html>' ) ;
355
355
} ) ;
356
+
357
+ it ( 'localizes end-to-end for password reset success' , async ( ) => {
358
+ await reconfigureServer ( config ) ;
359
+ const sendPasswordResetEmail = spyOn ( config . emailAdapter , 'sendPasswordResetEmail' ) . and . callThrough ( ) ;
360
+ const user = new Parse . User ( ) ;
361
+ user . setUsername ( 'exampleUsername' ) ;
362
+ user . setPassword ( 'examplePassword' ) ;
363
+ user . set ( 'email' , '[email protected] ' ) ;
364
+ await user . signUp ( ) ;
365
+ await Parse . User . requestPasswordReset ( user . getEmail ( ) ) ;
366
+
367
+ const link = sendPasswordResetEmail . calls . all ( ) [ 0 ] . args [ 0 ] . link ;
368
+ const linkWithLocale = new URL ( link ) ;
369
+ linkWithLocale . searchParams . append ( pageParams . locale , 'de-AT' ) ;
370
+
371
+ const linkResponse = await request ( {
372
+ url : linkWithLocale . toString ( ) ,
373
+ followRedirects : false ,
374
+ } ) ;
375
+ expect ( linkResponse . status ) . toBe ( 200 ) ;
376
+
377
+ const appId = linkResponse . headers [ 'x-parse-page-param-appid' ] ;
378
+ const token = linkResponse . headers [ 'x-parse-page-param-token' ] ;
379
+ const locale = linkResponse . headers [ 'x-parse-page-param-locale' ] ;
380
+ const username = linkResponse . headers [ 'x-parse-page-param-username' ] ;
381
+ const publicServerUrl = linkResponse . headers [ 'x-parse-page-param-publicserverurl' ] ;
382
+ const choosePasswordPagePath = pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ;
383
+ expect ( appId ) . toBeDefined ( ) ;
384
+ expect ( token ) . toBeDefined ( ) ;
385
+ expect ( locale ) . toBeDefined ( ) ;
386
+ expect ( username ) . toBeDefined ( ) ;
387
+ expect ( publicServerUrl ) . toBeDefined ( ) ;
388
+ expect ( choosePasswordPagePath ) . toMatch (
389
+ new RegExp ( `\/de-AT\/${ pages . choosePassword . defaultFile } ` )
390
+ ) ;
391
+ pageResponse . calls . reset ( ) ;
392
+
393
+ const formUrl = `${ publicServerUrl } /apps/${ appId } /request_password_reset` ;
394
+ const formResponse = await request ( {
395
+ url : formUrl ,
396
+ method : 'POST' ,
397
+ body : {
398
+ token,
399
+ locale,
400
+ username,
401
+ new_password : 'newPassword' ,
402
+ } ,
403
+ headers : {
404
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
405
+ } ,
406
+ followRedirects : false ,
407
+ } ) ;
408
+ expect ( formResponse . status ) . toEqual ( 200 ) ;
409
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toContain ( `/${ locale } /password_reset_success.html` ) ;
410
+ } ) ;
356
411
} ) ;
357
412
} ) ;
358
413
} ) ;
0 commit comments