Skip to content

Commit

Permalink
Making ScheduleExpirationNoticeMailjetEmailJob work for Particulier
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelfaure committed Aug 16, 2023
1 parent e2dbbf6 commit a134ad7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/jobs/schedule_expiration_notice_mailjet_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 25 additions & 2 deletions spec/jobs/schedule_expiration_notice_mailjet_email_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit a134ad7

Please sign in to comment.