Skip to content

Commit

Permalink
feat(email): add update personal info smtp email
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Oct 28, 2024
1 parent 932809a commit a8c0823
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 67 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/update_personal_information/fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ INSERT INTO users
(id, email, email_verified, email_verified_at, encrypted_password, created_at, updated_at, given_name, family_name,
phone_number, job)
VALUES
(1, '[email protected]', true, CURRENT_TIMESTAMP, '$2a$10$kzY3LINL6..50Fy9shWCcuNlRfYq0ft5lS.KCcJ5PzrhlWfKK4NIO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Rebibi', 'Dumama', '0123456789', 'Sbirette');
(1, '[email protected]', true, CURRENT_TIMESTAMP, '$2a$10$kzY3LINL6..50Fy9shWCcuNlRfYq0ft5lS.KCcJ5PzrhlWfKK4NIO', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'Konrad', 'Curze', '0404040404', 'Primarque');

INSERT INTO organizations
(id, siret, created_at, updated_at)
Expand Down
41 changes: 15 additions & 26 deletions cypress/e2e/update_personal_information/index.cy.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
describe("Signup into new entreprise unipersonnelle", () => {
before(() => {
cy.mailslurp().then((mailslurp) =>
mailslurp.inboxController.deleteAllInboxEmails({
inboxId: "9023e9f4-4e54-4ba0-9558-3cb61e7608c6",
}),
);
});

it("Should send email when user updates personal information", function () {
cy.visit("/personal-information");

cy.login("[email protected]");
cy.login("[email protected]");

cy.visit("/personal-information");

cy.contains("Vos informations personnelles");

cy.get('input[name="given_name"]').clear().type("Mister Rebecco");
cy.get('input[name="given_name"]').clear().type("Night");
cy.get('input[name="family_name"]').clear().type("Haunter");

cy.get('[type="submit"]').contains("Mettre à jour").click();

cy.contains("Vos informations ont été mises à jour.");

cy.mailslurp()
// use inbox id and a timeout of 30 seconds
.then((mailslurp) =>
mailslurp.waitForLatestEmail(
"9023e9f4-4e54-4ba0-9558-3cb61e7608c6",
60000,
true,
),
)
// check subject of deletion email
.then((email) => {
expect(email.subject).to.include(
"Mise à jour de vos données personnelles",
);
});
cy.maildevGetMessageBySubject(
"Mise à jour de vos données personnelles",
).then((email) => {
cy.maildevVisitMessageById(email.id);
cy.contains(
"Nous vous informons que vos données personnelles ont été mises à jour avec succès.",
);
cy.contains("Prénom : Night");
cy.contains("Nom de famille : Haunter");
cy.maildevDeleteMessageById(email.id);
});
});

it("should show an error where putting invalid names or job", () => {
cy.visit("/personal-information");

cy.login("[email protected]");
cy.login("[email protected]");

["given_name", "family_name", "job"].forEach((inputName) => {
cy.get(`input[name="${inputName}"]`).clear().type("​");
Expand Down
3 changes: 1 addition & 2 deletions src/connectors/brevo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type LocalTemplateSlug =
| "delete-access-key"
| "add-access-key"
| "update-totp-application"
| "add-2fa"
| "update-personal-data";
| "add-2fa";

// active templates id are listed at https://app-smtp.brevo.com/templates
const remoteTemplateSlugToBrevoTemplateId: {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const postPersonalInformationsController = async (
},
);

sendUpdatePersonalInformationEmail({
await sendUpdatePersonalInformationEmail({
previousInformations: getUserFromAuthenticatedSession(req),
newInformation: updatedUser,
});
Expand Down
11 changes: 8 additions & 3 deletions src/managers/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Delete2faProtection,
DeleteFreeTotpMail,
UpdatePersonalDataMail,
} from "@numerique-gouv/moncomptepro.email";
import { isEmpty } from "lodash-es";
import {
Expand Down Expand Up @@ -367,11 +368,15 @@ export const sendUpdatePersonalInformationEmail = async ({
}

if (previousInformations !== newInformation) {
return legacySendMail({
return sendMail({
to: [email],
subject: "Mise à jour de vos données personnelles",
template: "update-personal-data",
params: { given_name, family_name, updatedFields },
html: UpdatePersonalDataMail({
baseurl: MONCOMPTEPRO_HOST,
family_name,
given_name,
updatedFields: updatedFields,
}).toString(),
});
}
};
Expand Down
34 changes: 0 additions & 34 deletions src/views/mails/update-personal-data.ejs

This file was deleted.

0 comments on commit a8c0823

Please sign in to comment.