From a134ad782ad764d5f832c141408a7d423dc5ff9b Mon Sep 17 00:00:00 2001 From: Samuelfaure Date: Mon, 7 Aug 2023 13:07:25 +0200 Subject: [PATCH] Making ScheduleExpirationNoticeMailjetEmailJob work for Particulier --- ...ule_expiration_notice_mailjet_email_job.rb | 4 +-- ...xpiration_notice_mailjet_email_job_spec.rb | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/jobs/schedule_expiration_notice_mailjet_email_job.rb b/app/jobs/schedule_expiration_notice_mailjet_email_job.rb index 64a4fac50d..20db3fb348 100644 --- a/app/jobs/schedule_expiration_notice_mailjet_email_job.rb +++ b/app/jobs/schedule_expiration_notice_mailjet_email_job.rb @@ -22,8 +22,8 @@ def perform(token_id, expires_in) def build_message(token, expires_in) { - from_name: 'API Entreprise', - from_email: APIEntrepriseMailer.default_params[:from], + from_name: from_name(token.api), + from_email: from_email(token.api), to: build_recipients(token), vars: build_vars(token), 'Mj-TemplateLanguage' => true, diff --git a/spec/jobs/schedule_expiration_notice_mailjet_email_job_spec.rb b/spec/jobs/schedule_expiration_notice_mailjet_email_job_spec.rb index 52eade122a..231136a728 100644 --- a/spec/jobs/schedule_expiration_notice_mailjet_email_job_spec.rb +++ b/spec/jobs/schedule_expiration_notice_mailjet_email_job_spec.rb @@ -46,8 +46,8 @@ it 'calls Mailjet client with valid params' do expect(Mailjet::Send).to receive(:create).with( { - from_name: anything, - from_email: anything, + from_name: 'API Entreprise', + from_email: APIEntrepriseMailer.default_params[:from], to: "#{demandeur.full_name} <#{demandeur.email}>, #{contact.full_name} <#{contact.email}>", vars: { cadre_utilisation_token: token.intitule, @@ -62,6 +62,29 @@ subject end + context 'when token is for API Particulier' do + let(:authorization_request) { create(:authorization_request, :with_demandeur, :with_contact_technique, api: 'particulier') } + + it 'calls Mailjet client with valid params' do + expect(Mailjet::Send).to receive(:create).with( + { + from_name: 'API Particulier', + from_email: APIParticulierMailer.default_params[:from], + to: "#{demandeur.full_name} <#{demandeur.email}>, #{contact.full_name} <#{contact.email}>", + vars: { + cadre_utilisation_token: token.intitule, + authorization_request_id: external_id, + expiration_date: "#{Time.zone.at(token.exp).strftime('%d/%m/%Y à %Hh%M')} (heure de Paris)" + }, + 'Mj-TemplateLanguage' => true, + 'Mj-TemplateID' => 3_139_223 + }.stringify_keys + ) + + subject + end + end + context 'when Mailjet raises an error' do let(:mailjet_error) do Mailjet::ApiError.new(