Skip to content

Commit

Permalink
fix(api): send ail with correct locale and lang
Browse files Browse the repository at this point in the history
Co-Authored-By: Jérémy PLUQUET <[email protected]>
  • Loading branch information
theotime2005 and P-Jeremy committed Feb 19, 2025
1 parent c701eea commit 23230ca
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import { mailer } from '../../../shared/mail/infrastructure/services/mailer.js';
export function createWarningConnectionEmail({ locale, email, firstName, validationToken }) {
locale = locale || LOCALE.FRENCH_FRANCE;
const lang = new Intl.Locale(locale).language;
const factory = new EmailFactory({ app: 'pix-app', locale });
let localeSupport;
if (locale.toLowerCase() === LOCALE.FRENCH_FRANCE) {
localeSupport = LOCALE.FRENCH_FRANCE;
} else {
localeSupport = lang;
}

const factory = new EmailFactory({ app: 'pix-app', locale: localeSupport });

const { i18n, defaultVariables } = factory;
const pixAppUrl = urlBuilder.getPixAppBaseUrl(locale);
Expand All @@ -30,7 +37,7 @@ export function createWarningConnectionEmail({ locale, email, firstName, validat
homeName: defaultVariables.homeName,
homeUrl: defaultVariables.homeUrl,
helpDeskUrl: urlBuilder.getEmailValidationUrl({
locale,
locale: localeSupport,
redirectUrl: defaultVariables.helpdeskUrl,
token: validationToken,
}),
Expand All @@ -44,7 +51,11 @@ export function createWarningConnectionEmail({ locale, email, firstName, validat
disclaimer: i18n.__('warning-connection-email.params.disclaimer'),
warningMessage: i18n.__('warning-connection-email.params.warningMessage'),
resetMyPassword: i18n.__('warning-connection-email.params.resetMyPassword'),
resetUrl: urlBuilder.getEmailValidationUrl({ locale, redirectUrl: resetUrl, token: validationToken }),
resetUrl: urlBuilder.getEmailValidationUrl({
locale: localeSupport,
redirectUrl: resetUrl,
token: validationToken,
}),
supportContact: i18n.__('warning-connection-email.params.supportContact'),
thanks: i18n.__('warning-connection-email.params.thanks'),
signing: i18n.__('warning-connection-email.params.signing'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Unit | Identity Access Management | Domain | Email | create-warning-co
});

describe('when the locale is en', function () {
it('provides the correct reset password URL', function () {
it('provides the correct urls', function () {
// given
const emailParams = {
email: '[email protected]',
Expand All @@ -54,34 +54,19 @@ describe('Unit | Identity Access Management | Domain | Email | create-warning-co
const email = createWarningConnectionEmail(emailParams);

// then
const { resetUrl } = email.variables;
const expectedUrl =
'https://app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fapp.pix.org%2Fmot-de-passe-oublie%3Flang%3Den';
expect(resetUrl).to.equal(expectedUrl);
});

it('provides the correct help desk URL', function () {
// given
const emailParams = {
email: '[email protected]',
locale: 'en',
firstName: 'John',
validationToken: 'token',
};

// when
const email = createWarningConnectionEmail(emailParams);

// then
const { helpDeskUrl } = email.variables;
const expectedUrl =
'https://app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.org%2Fen%2Fsupport';
expect(helpDeskUrl).to.equal(expectedUrl);
const { helpDeskUrl, resetUrl } = email.variables;
const expectedSupportUrl =
'https://test.app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.org%2Fen%2Fsupport';

const expectedResetUrl =
'https://test.app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Ftest.app.pix.org%2Fmot-de-passe-oublie%3Flang%3Den';
expect(resetUrl).to.equal(expectedResetUrl);
expect(helpDeskUrl).to.equal(expectedSupportUrl);
});
});

describe('when the locale is fr-fr', function () {
it('provides the correct reset password URL', function () {
it('provides the correct urls', function () {
// given
const emailParams = {
email: '[email protected]',
Expand All @@ -94,17 +79,22 @@ describe('Unit | Identity Access Management | Domain | Email | create-warning-co
const email = createWarningConnectionEmail(emailParams);

// then
const { resetUrl } = email.variables;
const expectedUrl =
'https://app.pix.fr/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fapp.pix.fr%2Fmot-de-passe-oublie%3Flang%3Dfr';
expect(resetUrl).to.equal(expectedUrl);
const { helpDeskUrl, resetUrl } = email.variables;
const expectedSupportUrl =
'https://test.app.pix.fr/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.fr%2Fsupport';
const expectedResetUrl =
'https://test.app.pix.fr/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Ftest.app.pix.fr%2Fmot-de-passe-oublie%3Flang%3Dfr';
expect(resetUrl).to.equal(expectedResetUrl);
expect(helpDeskUrl).to.equal(expectedSupportUrl);
});
});

it('provides the correct help desk URL', function () {
describe('when the locale is fr', function () {
it('provides the correct urls', function () {
// given
const emailParams = {
email: '[email protected]',
locale: 'fr-fr',
locale: 'fr',
firstName: 'John',
validationToken: 'token',
};
Expand All @@ -113,15 +103,18 @@ describe('Unit | Identity Access Management | Domain | Email | create-warning-co
const email = createWarningConnectionEmail(emailParams);

// then
const { helpDeskUrl } = email.variables;
const expectedUrl =
'https://app.pix.fr/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.fr%2Fsupport';
expect(helpDeskUrl).to.equal(expectedUrl);
const { helpDeskUrl, resetUrl } = email.variables;
const expectedSupportUrl =
'https://test.app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.org%2Ffr%2Fsupport';
const expectedResetUrl =
'https://test.app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Ftest.app.pix.org%2Fmot-de-passe-oublie%3Flang%3Dfr';
expect(resetUrl).to.equal(expectedResetUrl);
expect(helpDeskUrl).to.equal(expectedSupportUrl);
});
});

describe('when the locale is nl-BE', function () {
it('provides the correct reset password URL', function () {
it('provides the correct urls', function () {
// given
const emailParams = {
email: '[email protected]',
Expand All @@ -134,11 +127,14 @@ describe('Unit | Identity Access Management | Domain | Email | create-warning-co
const email = createWarningConnectionEmail(emailParams);

// then
const { resetUrl } = email.variables;
const expectedUrl =
'https://app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fapp.pix.org%2Fmot-de-passe-oublie%3Flang%3Dnl';

expect(resetUrl).to.equal(expectedUrl);
const { resetUrl, helpDeskUrl } = email.variables;
const expectedResetUrl =
'https://test.app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Ftest.app.pix.org%2Fmot-de-passe-oublie%3Flang%3Dnl';

const expectedSupportUrl =
'https://test.app.pix.org/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.org%2Fnl-be%2Fsupport';
expect(resetUrl).to.equal(expectedResetUrl);
expect(helpDeskUrl).to.equal(expectedSupportUrl);
});
});
});

0 comments on commit 23230ca

Please sign in to comment.