Skip to content

Commit 69147f5

Browse files
committed
test: Add tests for emailVerifySuccessOnInvalidEmail: false
Add parallel tests that explicitly set emailVerifySuccessOnInvalidEmail to false to verify the fail page is shown, covering both settings.
1 parent b3d5f88 commit 69147f5

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

spec/PagesRouter.spec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,67 @@ describe('Pages Router', () => {
847847
);
848848
});
849849

850+
it('localizes end-to-end for verify email: invalid verification link - link send fail with emailVerifySuccessOnInvalidEmail disabled', async () => {
851+
config.emailVerifySuccessOnInvalidEmail = false;
852+
await reconfigureServer(config);
853+
const sendVerificationEmail = spyOn(
854+
config.emailAdapter,
855+
'sendVerificationEmail'
856+
).and.callThrough();
857+
const user = new Parse.User();
858+
user.setUsername('exampleUsername');
859+
user.setPassword('examplePassword');
860+
user.set('email', 'mail@example.com');
861+
await user.signUp();
862+
await jasmine.timeout();
863+
864+
const link = sendVerificationEmail.calls.all()[0].args[0].link;
865+
const linkWithLocale = new URL(link);
866+
linkWithLocale.searchParams.append(pageParams.locale, exampleLocale);
867+
linkWithLocale.searchParams.set(pageParams.token, 'invalidToken');
868+
869+
const linkResponse = await request({
870+
url: linkWithLocale.toString(),
871+
followRedirects: false,
872+
});
873+
expect(linkResponse.status).toBe(200);
874+
875+
const appId = linkResponse.headers['x-parse-page-param-appid'];
876+
const locale = linkResponse.headers['x-parse-page-param-locale'];
877+
const publicServerUrl = linkResponse.headers['x-parse-page-param-publicserverurl'];
878+
await jasmine.timeout();
879+
880+
const invalidVerificationPagePath = pageResponse.calls.all()[0].args[0];
881+
expect(appId).toBeDefined();
882+
expect(locale).toBe(exampleLocale);
883+
expect(publicServerUrl).toBeDefined();
884+
expect(invalidVerificationPagePath).toMatch(
885+
new RegExp(`\/${exampleLocale}\/${pages.emailVerificationLinkInvalid.defaultFile}`)
886+
);
887+
888+
spyOn(UserController.prototype, 'resendVerificationEmail').and.callFake(() =>
889+
Promise.reject('failed to resend verification email')
890+
);
891+
892+
const formUrl = `${publicServerUrl}/apps/${appId}/resend_verification_email`;
893+
const formResponse = await request({
894+
url: formUrl,
895+
method: 'POST',
896+
body: {
897+
locale,
898+
username: 'exampleUsername',
899+
},
900+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
901+
followRedirects: false,
902+
});
903+
expect(formResponse.status).toEqual(303);
904+
// With emailVerifySuccessOnInvalidEmail: false, the resend page
905+
// redirects to the fail page
906+
expect(formResponse.text).toContain(
907+
`/${locale}/${pages.emailVerificationSendFail.defaultFile}`
908+
);
909+
});
910+
850911
it('localizes end-to-end for resend verification email: invalid link', async () => {
851912
await reconfigureServer(config);
852913
const formUrl = `${config.publicServerURL}/apps/${config.appId}/resend_verification_email`;

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,33 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
768768
});
769769
});
770770

771+
it('redirects you to link send fail page if you try to resend a link for a nonexistent user with emailVerifySuccessOnInvalidEmail disabled', done => {
772+
reconfigureServer({
773+
appName: 'emailing app',
774+
verifyUserEmails: true,
775+
emailVerifySuccessOnInvalidEmail: false,
776+
emailAdapter: {
777+
sendVerificationEmail: () => Promise.resolve(),
778+
sendPasswordResetEmail: () => Promise.resolve(),
779+
sendMail: () => {},
780+
},
781+
publicServerURL: 'http://localhost:8378/1',
782+
}).then(() => {
783+
request({
784+
url: 'http://localhost:8378/1/apps/test/resend_verification_email',
785+
method: 'POST',
786+
followRedirects: false,
787+
body: {
788+
username: 'sadfasga',
789+
},
790+
}).then(response => {
791+
expect(response.status).toEqual(303);
792+
expect(response.text).toContain('email_verification_send_fail.html');
793+
done();
794+
});
795+
});
796+
});
797+
771798
it('does not update email verified if you use an invalid token', done => {
772799
const user = new Parse.User();
773800
const emailAdapter = {

0 commit comments

Comments
 (0)