From 9215596578657612184b1627e202e1cf47e74c6e Mon Sep 17 00:00:00 2001 From: Theotime2005 Date: Fri, 14 Feb 2025 16:13:24 +0100 Subject: [PATCH] fix(api): send ail with correct locale and lang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Jérémy PLUQUET <37305474+P-Jeremy@users.noreply.github.com> --- .../emails/create-warning-connection.email.js | 8 ++- .../create-warning-connection.email.test.js | 72 ++++++------------- 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/api/src/identity-access-management/domain/emails/create-warning-connection.email.js b/api/src/identity-access-management/domain/emails/create-warning-connection.email.js index 56ff281ac02..d5166876058 100644 --- a/api/src/identity-access-management/domain/emails/create-warning-connection.email.js +++ b/api/src/identity-access-management/domain/emails/create-warning-connection.email.js @@ -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'; @@ -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); @@ -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, }), diff --git a/api/tests/identity-access-management/unit/domain/emails/create-warning-connection.email.test.js b/api/tests/identity-access-management/unit/domain/emails/create-warning-connection.email.test.js index 4898ea4f892..9c2beea667a 100644 --- a/api/tests/identity-access-management/unit/domain/emails/create-warning-connection.email.test.js +++ b/api/tests/identity-access-management/unit/domain/emails/create-warning-connection.email.test.js @@ -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: 'toto@example.net', @@ -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: 'toto@example.net', - 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: 'toto@example.net', @@ -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: 'toto@example.net', - 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: 'toto@example.net', @@ -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); }); }); });