Skip to content

Commit

Permalink
feat(api): translate title with firstname for account creation email
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetetot committed Jul 11, 2024
1 parent eb6f44c commit 0d8d6a1
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const createAndReconcileUserToOrganizationLearner = async function (
password: payload.password,
campaignCode: payload['campaign-code'],
locale,
i18n: request.i18n,
});

return h.response().code(204);
Expand Down
3 changes: 2 additions & 1 deletion api/lib/domain/services/mail-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const PIX_HELPDESK_URL_INTERNATIONAL = {
* @param redirectionUrl
* @returns {Promise<EmailingAttempt>}
*/
function sendAccountCreationEmail({ email, firstName, locale = FRENCH_FRANCE, token, redirectionUrl }) {
function sendAccountCreationEmail({ email, firstName, locale = FRENCH_FRANCE, token, redirectionUrl, i18n }) {
const mailerConfig = _getMailerConfig(locale);
const redirectUrl = redirectionUrl || mailerConfig.pixAppConnectionUrl;

Expand All @@ -61,6 +61,7 @@ function sendAccountCreationEmail({ email, firstName, locale = FRENCH_FRANCE, to
helpdeskUrl: mailerConfig.helpdeskUrl,
displayNationalLogo: mailerConfig.displayNationalLogo,
...mailerConfig.translation['pix-account-creation-email'].params,
title: i18n.__({ phrase: 'pix-account-creation-email.params.title', locale }, { firstName }),
};
const pixName = mailerConfig.translation['email-sender-name']['pix-app'];
const accountCreationEmailSubject = mailerConfig.translation['pix-account-creation-email'].subject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const createAndReconcileUserToOrganizationLearner = async function ({
userService,
passwordValidator,
userValidator,
i18n,
}) {
const campaign = await campaignRepository.getByCode(campaignCode);
if (!campaign) {
Expand Down Expand Up @@ -89,6 +90,7 @@ const createAndReconcileUserToOrganizationLearner = async function ({
locale,
token,
redirectionUrl,
i18n,
});
}
return createdUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const save = async function (request, h, dependencies = { userSerializer, reques
password,
campaignCode,
localeFromHeader,
i18n: request.i18n,
});

return h.response(dependencies.userSerializer.serialize(savedUser)).created();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const createUser = async function ({
userService,
userValidator,
passwordValidator,
i18n,
}) {
const isValid = await _validateData({
password,
Expand Down Expand Up @@ -74,6 +75,7 @@ const createUser = async function ({
locale: localeFromHeader,
token,
redirectionUrl,
i18n,
});

return savedUser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { identityAccessManagementRoutes } from '../../../../src/identity-access-management/application/routes.js';
import * as i18nPlugin from '../../../../src/shared/infrastructure/plugins/i18n.js';
import { expect, HttpTestServer } from '../../../test-helper.js';

const routesUnderTest = identityAccessManagementRoutes[0];
Expand All @@ -8,6 +9,7 @@ describe('Integration | Identity Access Management | Application | Route | User'

beforeEach(async function () {
httpTestServer = new HttpTestServer();
await httpTestServer.register(i18nPlugin);
await httpTestServer.register(routesUnderTest);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { User } from '../../../../../src/identity-access-management/domain/models/User.js';
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
import { expect } from '../../../../test-helper.js';
import { getI18n } from '../../../../tooling/i18n/i18n.js';

describe('Integration | Identity Access Management | Domain | UseCase | create-user', function () {
it('returns the saved user', async function () {
Expand All @@ -10,7 +11,7 @@ describe('Integration | Identity Access Management | Domain | UseCase | create-u
const password = 'P@ssW0rd';

// when
const savedUser = await usecases.createUser({ password, user });
const savedUser = await usecases.createUser({ password, user, i18n: getI18n() });

// then
expect(savedUser).to.be.instanceOf(User);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ describe('Unit | Identity Access Management | Application | Controller | User',
password,
localeFromHeader,
campaignCode: null,
i18n: undefined,
};

dependencies.localeService.getCanonicalLocale.returns(localeFromCookie);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ describe('Unit | Identity Access Management | Domain | UseCase | create-user', f
locale: localeFromHeader,
token,
redirectionUrl: expectedRedirectionUrl,
i18n: undefined,
});
});

Expand Down Expand Up @@ -508,6 +509,7 @@ describe('Unit | Identity Access Management | Domain | UseCase | create-user', f
locale: localeFromHeader,
token,
redirectionUrl: expectedRedirectionUrl,
i18n: undefined,
});
});
});
Expand Down Expand Up @@ -545,6 +547,7 @@ describe('Unit | Identity Access Management | Domain | UseCase | create-user', f
locale: localeFromHeader,
token,
redirectionUrl: expectedRedirectionUrl,
i18n: undefined,
});
});
});
Expand Down Expand Up @@ -583,6 +586,7 @@ describe('Unit | Identity Access Management | Domain | UseCase | create-user', f
locale: localeFromHeader,
token,
redirectionUrl,
i18n: undefined,
});
expect(createdUser).to.deep.equal(savedUser);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import * as userService from '../../../../src/shared/domain/services/user-servic
import * as passwordValidator from '../../../../src/shared/domain/validators/password-validator.js';
import * as userValidator from '../../../../src/shared/domain/validators/user-validator.js';
import { catchErr, databaseBuilder, expect } from '../../../test-helper.js';
import { getI18n } from '../../../tooling/i18n/i18n.js';

const i18n = getI18n();

describe('Integration | UseCases | create-and-reconcile-user-to-organization-learner', function () {
const pickUserAttributes = ['firstName', 'lastName', 'email', 'username', 'cgu'];
Expand Down Expand Up @@ -50,6 +53,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
obfuscationService,
userReconciliationService,
userService,
i18n,
});

// then
Expand Down Expand Up @@ -86,6 +90,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
obfuscationService,
userReconciliationService,
userService,
i18n,
});

// then
Expand Down Expand Up @@ -135,6 +140,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
obfuscationService,
userReconciliationService,
userService,
i18n,
});

// then
Expand Down Expand Up @@ -195,6 +201,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
userService,
passwordValidator,
userValidator,
i18n,
});

// then
Expand Down Expand Up @@ -238,6 +245,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
obfuscationService,
userReconciliationService,
userService,
i18n,
});

// then
Expand All @@ -258,6 +266,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
locale,
password,
userAttributes,
i18n,
});

// then
Expand Down Expand Up @@ -325,6 +334,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
obfuscationService,
userReconciliationService,
userService,
i18n,
});

// then
Expand Down Expand Up @@ -366,6 +376,7 @@ describe('Integration | UseCases | create-and-reconcile-user-to-organization-lea
userService,
passwordValidator,
userValidator,
i18n,
});

// then
Expand Down
Loading

0 comments on commit 0d8d6a1

Please sign in to comment.