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 14, 2025
1 parent d430c9a commit 9215596
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { log } from 'debug';

import { LOCALE } from '../../../shared/domain/constants.js';
import { urlBuilder } from '../../../shared/infrastructure/utils/url-builder.js';
import { EmailFactory } from '../../../shared/mail/domain/models/EmailFactory.js';
Expand All @@ -16,7 +18,9 @@ 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 });
const localeSupport = locale === LOCALE.FRENCH_FRANCE ? LOCALE.FRENCH_FRANCE : lang;

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

const { i18n, defaultVariables } = factory;
const pixAppUrl = urlBuilder.getPixAppBaseUrl(locale);
Expand All @@ -30,7 +34,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 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 =
const { helpDeskUrl, resetUrl } = email.variables;
const expectedSupportUrl =
'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 expectedResetUrl =
'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(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,34 +79,18 @@ 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);
});

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

// when
const email = createWarningConnectionEmail(emailParams);

// then
const { helpDeskUrl } = email.variables;
const expectedUrl =
const { helpDeskUrl, resetUrl } = email.variables;
const expectedSupportUrl =
'https://app.pix.fr/api/users/validate-email?token=token&redirect_url=https%3A%2F%2Fpix.fr%2Fsupport';
expect(helpDeskUrl).to.equal(expectedUrl);
const expectedResetUrl =
'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(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 +103,14 @@ describe('Unit | Identity Access Management | Domain | Email | create-warning-co
const email = createWarningConnectionEmail(emailParams);

// then
const { resetUrl } = email.variables;
const expectedUrl =
const { resetUrl, helpDeskUrl } = email.variables;
const expectedResetUrl =
'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 expectedSupportUrl =
'https://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 9215596

Please sign in to comment.