@@ -63,7 +63,7 @@ describe('Pages Router', () => {
63
63
expect ( response . status ) . toBe ( 200 ) ;
64
64
} ) ;
65
65
66
- it ( 'responds with 404 if publicServerURL is not confgured ' , async ( ) => {
66
+ it ( 'responds with 404 if publicServerURL is not configured ' , async ( ) => {
67
67
await reconfigureServer ( {
68
68
appName : 'unused' ,
69
69
pages : { enableRouter : true } ,
@@ -971,5 +971,82 @@ describe('Pages Router', () => {
971
971
expect ( response . text ) . toBe ( 'Not found.' ) ;
972
972
} ) ;
973
973
} ) ;
974
+
975
+ describe ( 'custom endpoint' , ( ) => {
976
+ it ( 'password reset works with custom endpoint' , async ( ) => {
977
+ config . pages . pagesEndpoint = 'customEndpoint' ;
978
+ await reconfigureServer ( config ) ;
979
+ const sendPasswordResetEmail = spyOn (
980
+ config . emailAdapter ,
981
+ 'sendPasswordResetEmail'
982
+ ) . and . callThrough ( ) ;
983
+ const user = new Parse . User ( ) ;
984
+ user . setUsername ( 'exampleUsername' ) ;
985
+ user . setPassword ( 'examplePassword' ) ;
986
+ user . set ( 'email' , 'mail@example.com' ) ;
987
+ await user . signUp ( ) ;
988
+ await Parse . User . requestPasswordReset ( user . getEmail ( ) ) ;
989
+
990
+ const link = sendPasswordResetEmail . calls . all ( ) [ 0 ] . args [ 0 ] . link ;
991
+ const linkResponse = await request ( {
992
+ url : link ,
993
+ followRedirects : false ,
994
+ } ) ;
995
+ expect ( linkResponse . status ) . toBe ( 200 ) ;
996
+
997
+ const appId = linkResponse . headers [ 'x-parse-page-param-appid' ] ;
998
+ const token = linkResponse . headers [ 'x-parse-page-param-token' ] ;
999
+ const username = linkResponse . headers [ 'x-parse-page-param-username' ] ;
1000
+ const publicServerUrl = linkResponse . headers [ 'x-parse-page-param-publicserverurl' ] ;
1001
+ const passwordResetPagePath = pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ;
1002
+ expect ( appId ) . toBeDefined ( ) ;
1003
+ expect ( token ) . toBeDefined ( ) ;
1004
+ expect ( username ) . toBeDefined ( ) ;
1005
+ expect ( publicServerUrl ) . toBeDefined ( ) ;
1006
+ expect ( passwordResetPagePath ) . toMatch ( new RegExp ( `\/${ pages . passwordReset . defaultFile } ` ) ) ;
1007
+ pageResponse . calls . reset ( ) ;
1008
+
1009
+ const formUrl = `${ publicServerUrl } /${ config . pages . pagesEndpoint } /${ appId } /request_password_reset` ;
1010
+ const formResponse = await request ( {
1011
+ url : formUrl ,
1012
+ method : 'POST' ,
1013
+ body : {
1014
+ token,
1015
+ username,
1016
+ new_password : 'newPassword' ,
1017
+ } ,
1018
+ headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
1019
+ followRedirects : false ,
1020
+ } ) ;
1021
+ expect ( formResponse . status ) . toEqual ( 200 ) ;
1022
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toContain (
1023
+ `/${ pages . passwordResetSuccess . defaultFile } `
1024
+ ) ;
1025
+ } ) ;
1026
+
1027
+ it ( 'email verification works with custom endpoint' , async ( ) => {
1028
+ config . pages . pagesEndpoint = 'customEndpoint' ;
1029
+ await reconfigureServer ( config ) ;
1030
+ const sendVerificationEmail = spyOn (
1031
+ config . emailAdapter ,
1032
+ 'sendVerificationEmail'
1033
+ ) . and . callThrough ( ) ;
1034
+ const user = new Parse . User ( ) ;
1035
+ user . setUsername ( 'exampleUsername' ) ;
1036
+ user . setPassword ( 'examplePassword' ) ;
1037
+ user . set ( 'email' , 'mail@example.com' ) ;
1038
+ await user . signUp ( ) ;
1039
+
1040
+ const link = sendVerificationEmail . calls . all ( ) [ 0 ] . args [ 0 ] . link ;
1041
+ const linkResponse = await request ( {
1042
+ url : link ,
1043
+ followRedirects : false ,
1044
+ } ) ;
1045
+ expect ( linkResponse . status ) . toBe ( 200 ) ;
1046
+
1047
+ const pagePath = pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ;
1048
+ expect ( pagePath ) . toMatch ( new RegExp ( `\/${ pages . emailVerificationSuccess . defaultFile } ` ) ) ;
1049
+ } ) ;
1050
+ } ) ;
974
1051
} ) ;
975
1052
} ) ;
0 commit comments