Skip to content

Commit 76fe0ca

Browse files
committed
added end-to-end localizaton test
1 parent 9748fb3 commit 76fe0ca

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

spec/PublicAPI.spec.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const request = require('../lib/request');
44
const fs = require('fs').promises;
55
const Utils = require('../lib/Utils');
6-
const { PublicAPIRouter, pages } = require('../lib/Routers/PublicAPIRouter');
6+
const { PublicAPIRouter, pages, pageParams } = require('../lib/Routers/PublicAPIRouter');
77

88
describe('public API', () => {
99
describe('basic request', () => {
@@ -328,7 +328,7 @@ describe('public API', () => {
328328
}
329329
});
330330

331-
it('responds to POST request with redirect response (e2e test)', async () => {
331+
it('responds to POST request with redirect response', async () => {
332332
await reconfigureServer(config);
333333
const response = await request({
334334
url:
@@ -342,7 +342,7 @@ describe('public API', () => {
342342
);
343343
});
344344

345-
it('responds to GET request with content response (e2e test)', async () => {
345+
it('responds to GET request with content response', async () => {
346346
await reconfigureServer(config);
347347
const response = await request({
348348
url:
@@ -353,6 +353,61 @@ describe('public API', () => {
353353
expect(response.status).toEqual(200);
354354
expect(response.text).toContain('<html>');
355355
});
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+
});
356411
});
357412
});
358413
});

0 commit comments

Comments
 (0)