Skip to content

Commit

Permalink
Bugfix: Always send docs to ZD if we can
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Dooner <[email protected]>
Co-authored-by: Jonathan Greenberg <[email protected]>
  • Loading branch information
3 people committed May 12, 2020
1 parent eba5c39 commit 922fa61
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
9 changes: 6 additions & 3 deletions app/jobs/send_completed_intake_to_zendesk_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ def perform(intake_id)
ensure_zendesk_ticket_on(intake)

service = ZendeskIntakeService.new(intake)
success = service.send_final_intake_pdf &&
service.send_bank_details_png &&
service.send_all_docs

sent_pdf = service.send_final_intake_pdf
sent_docs = service.send_all_docs
sent_bank_info = service.send_bank_details_png

success = sent_pdf && sent_docs && sent_bank_info
intake.update(completed_intake_sent_to_zendesk: success)
raise 'Unable send everything to Zendesk' unless success
end
end
end
2 changes: 1 addition & 1 deletion app/services/zendesk_intake_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def send_consent_pdf_with_spouse
end

def send_bank_details_png
return unless @intake.include_bank_details?
return true unless @intake.include_bank_details?

output = append_file_to_ticket(
ticket_id: @intake.intake_ticket_id,
Expand Down
21 changes: 20 additions & 1 deletion spec/jobs/send_completed_intake_to_zendesk_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@
end
end

context "when one of the three tasks fails" do
before do
allow(fake_zendesk_intake_service).to receive(:send_final_intake_pdf).and_return(false)
end

it "raises an error" do
expect do
described_class.perform_now(intake.id)
end.to raise_error(/Unable send everything to Zendesk/)

expect(ZendeskIntakeService).to have_received(:new).with(intake)
expect(fake_zendesk_intake_service).to have_received(:send_final_intake_pdf)
expect(fake_zendesk_intake_service).to have_received(:send_bank_details_png)
expect(fake_zendesk_intake_service).to have_received(:send_all_docs)
intake.reload
expect(intake.completed_intake_sent_to_zendesk).to eq false
end
end

it_behaves_like "catches exceptions with raven context", :send_final_intake_pdf
it_behaves_like 'a ticket-dependent job', ZendeskIntakeService
it_behaves_like "a ticket-dependent job", ZendeskIntakeService
end
end
5 changes: 3 additions & 2 deletions spec/services/zendesk_intake_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,11 @@
let(:payment_method) { "check" }
let(:pay_from_bank) { "no"}

it "does not attach a comment to the ticket" do
service.send_bank_details_png
it "does not attach a comment to the ticket and returns true" do
result = service.send_bank_details_png

expect(service).not_to have_received(:append_file_to_ticket)
expect(result).to eq true
end
end

Expand Down

0 comments on commit 922fa61

Please sign in to comment.