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 bca0292 commit 538ce2b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
end

describe 'with api Particulier' do
let(:authorization_request) { create(:authorization_request, status: authorization_request_status, api: 'particulier') }
let(:authorization_request_api) { 'particulier' }

it 'calls Mailjet client with valid params' do
expect(Mailjet::Send).to receive(:create).with(
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 538ce2b

Please sign in to comment.