From 2ac796ca231f0df25c8f29086d0748b877d74c0d Mon Sep 17 00:00:00 2001
From: LEGO Technix <109212476+lego-technix@users.noreply.github.com>
Date: Thu, 5 Dec 2024 11:05:23 +0100
Subject: [PATCH] feat(api): add self delete-user account notification email

---
 .../create-self-delete-user-account.email.js  | 25 +++++++++++++++
 ...ate-self-delete-user-account.email_test.js | 32 +++++++++++++++++++
 api/translations/en.json                      |  8 ++---
 3 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 api/src/identity-access-management/domain/emails/create-self-delete-user-account.email.js
 create mode 100644 api/tests/identity-access-management/unit/domain/emails/create-self-delete-user-account.email_test.js

diff --git a/api/src/identity-access-management/domain/emails/create-self-delete-user-account.email.js b/api/src/identity-access-management/domain/emails/create-self-delete-user-account.email.js
new file mode 100644
index 00000000000..8a0563a1e66
--- /dev/null
+++ b/api/src/identity-access-management/domain/emails/create-self-delete-user-account.email.js
@@ -0,0 +1,25 @@
+import { EmailFactory } from '../../../shared/mail/domain/models/EmailFactory.js';
+import { mailer } from '../../../shared/mail/infrastructure/services/mailer.js';
+
+export function createSelfDeleteUserAccountEmail({ locale, email, firstName }) {
+  const factory = new EmailFactory({ app: 'pix-app', locale });
+
+  const { i18n, defaultVariables } = factory;
+
+  return factory.buildEmail({
+    template: mailer.selfAccountDeletionTemplateId,
+    subject: i18n.__('self-account-deletion-email.subject'),
+    to: email,
+    variables: {
+      homeName: defaultVariables.homeName,
+      homeUrl: defaultVariables.homeUrl,
+      helpdeskUrl: defaultVariables.helpdeskUrl,
+      displayNationalLogo: defaultVariables.displayNationalLogo,
+      doNotAnswer: i18n.__('common.email.m doNotAnswer'),
+      moreOn: i18n.__('common.email.moreOn'),
+      pixPresentation: i18n.__('common.email.pixPresentation'),
+      title: i18n.__('self-account-deletion-email.params.title', { firstName }),
+      // "contactUs"
+    },
+  });
+}
diff --git a/api/tests/identity-access-management/unit/domain/emails/create-self-delete-user-account.email_test.js b/api/tests/identity-access-management/unit/domain/emails/create-self-delete-user-account.email_test.js
new file mode 100644
index 00000000000..b8c81fd74e7
--- /dev/null
+++ b/api/tests/identity-access-management/unit/domain/emails/create-self-delete-user-account.email_test.js
@@ -0,0 +1,32 @@
+import { createSelfDeleteUserAccountEmail } from '../../../../../src/identity-access-management/domain/emails/create-self-delete-user-account.email.js';
+import { Email } from '../../../../../src/shared/mail/domain/models/Email.js';
+import { mailer } from '../../../../../src/shared/mail/infrastructure/services/mailer.js';
+import { expect } from '../../../../test-helper.js';
+
+describe('Unit | Identity Access Management | Domain | Email | create-self-delete-user-account', function () {
+  it('creates self delete user account email with correct parameters', function () {
+    const emailParams = {
+      locale: 'fr',
+      email: 'test@example.com',
+      firstName: 'John',
+      token: '12345',
+    };
+
+    const email = createSelfDeleteUserAccountEmail(emailParams);
+
+    expect(email).to.be.instanceof(Email);
+    expect(email).to.have.property('subject').that.is.a('string');
+    expect(email.to).to.equal(emailParams.email);
+    expect(email.template).to.equal(mailer.selfAccountDeletionTemplateId);
+
+    const variables = email.variables;
+    expect(variables).to.have.property('displayNationalLogo').that.is.a('boolean');
+    expect(variables).to.have.property('doNotAnswer').that.is.a('string');
+    expect(variables).to.have.property('helpdeskUrl').that.is.a('string');
+    expect(variables).to.have.property('homeName').that.is.a('string');
+    expect(variables).to.have.property('homeUrl').that.is.a('string');
+    expect(variables).to.have.property('moreOn').that.is.a('string');
+    expect(variables).to.have.property('pixPresentation').that.is.a('string');
+    expect(variables).to.have.property('title').that.is.a('string');
+  });
+});
diff --git a/api/translations/en.json b/api/translations/en.json
index b31968a7f87..3e919e4cad3 100644
--- a/api/translations/en.json
+++ b/api/translations/en.json
@@ -386,11 +386,11 @@
   "self-account-deletion-email": {
     "params": {
       "hello": "Hello {firstName},",
-      "requestConfirmation": "Following your request, we can confirm that your Pix account and personal data have been deleted.",
-      "seeYouSoon": "We hope to see you soon for new digital adventures.",
-      "signing": "The Pix team",
+      "requestConfirmation": "XXX",
+      "seeYouSoon": "XXX",
+      "signing": "XXX",
       "title": "Deleting your account",
-      "warning": "If you are not the source of this request, please contact support."
+      "warning": "XXX"
     },
     "subject": "Deleting your account"
   },