diff --git a/server/src/domain/services/mail-service.js b/server/src/domain/services/mail-service.js index b476eed..5961e8d 100644 --- a/server/src/domain/services/mail-service.js +++ b/server/src/domain/services/mail-service.js @@ -6,11 +6,16 @@ const jobsAddedEmailTemplate = require('../../infrastructure/mailing/jobs-added- function sendInterestEmail(form) { const subject = `[JobBoard] ${form.interestedConsultant.name} intéressé·e par ${form.missionName} - ${form.activityName}`; const template = interestEmailTemplate.compile(form); + const mailTo = [config.MAIL_TO]; + if (form.businessContactNickname !== 'N/A') { + const businessContactEmail = `${form.businessContactNickname}@octo.com`; + mailTo.push(businessContactEmail); + } const options = { from: config.MAIL_FROM, fromName: 'Le Job Board - Ne pas répondre', - to: config.MAIL_TO, + to: mailTo, subject, template, }; diff --git a/server/test/unit/domain/services/mail-service.spec.js b/server/test/unit/domain/services/mail-service.spec.js index 09036b6..0439f44 100644 --- a/server/test/unit/domain/services/mail-service.spec.js +++ b/server/test/unit/domain/services/mail-service.spec.js @@ -26,7 +26,7 @@ describe('Unit | Service | MailService', () => { name: 'Samurai Jack', email: 'sjack@octo.com', }, - businessContactNickname: 'XYZ', + businessContactNickname: 'BusinessContactNickname', missionDirectorNickname: 'ZYX', octopodLink: 'https://octopod.octo.com/projects/2146904867', activityName: 'Développeur Front', @@ -40,7 +40,36 @@ describe('Unit | Service | MailService', () => { return promise.then(() => { expect(mailJet.sendEmail).to.have.been.calledWithExactly({ from: 'jobboard+test@octo.com', - to: 'jobboard+test@octo.com', + to: ['jobboard+test@octo.com', 'BusinessContactNickname@octo.com'], + fromName: 'Le Job Board - Ne pas répondre', + subject: '[JobBoard] Samurai Jack intéressé·e par Oodrive - Liste d\'initié - Développeur Front', + template: 'Interest mail template', + }); + }); + }); + + it('should not send an email to business contact if unknown', () => { + // given + const form = { + interestedConsultant: { + name: 'Samurai Jack', + email: 'sjack@octo.com', + }, + businessContactNickname: 'N/A', + missionDirectorNickname: 'ZYX', + octopodLink: 'https://octopod.octo.com/projects/2146904867', + activityName: 'Développeur Front', + missionName: 'Oodrive - Liste d\'initié', + }; + + // when + const promise = mailService.sendInterestEmail(form); + + // then + return promise.then(() => { + expect(mailJet.sendEmail).to.have.been.calledWithExactly({ + from: 'jobboard+test@octo.com', + to: ['jobboard+test@octo.com'], fromName: 'Le Job Board - Ne pas répondre', subject: '[JobBoard] Samurai Jack intéressé·e par Oodrive - Liste d\'initié - Développeur Front', template: 'Interest mail template',