From 9a8510dc6ebe15b6ebecfc6e19feb57278c0a329 Mon Sep 17 00:00:00 2001 From: tofarr Date: Thu, 8 Aug 2024 11:27:35 -0600 Subject: [PATCH] FYST-327 (#4684) * Using pregenerated pdf * Added spec to cover pre-generated pdf --- .../questions/submission_pdfs_controller.rb | 6 ++++++ .../questions/submission_pdfs_controller_spec.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/controllers/state_file/questions/submission_pdfs_controller.rb b/app/controllers/state_file/questions/submission_pdfs_controller.rb index 350fba9b8b..38f8de7e88 100644 --- a/app/controllers/state_file/questions/submission_pdfs_controller.rb +++ b/app/controllers/state_file/questions/submission_pdfs_controller.rb @@ -4,6 +4,12 @@ class SubmissionPdfsController < QuestionsController skip_before_action :redirect_if_in_progress_intakes_ended def show + if current_intake.submission_pdf.attached? + send_data current_intake.submission_pdf.download, filename: "submission.pdf", disposition: 'inline' + return + end + # This is a fallback for legacy reasons - all submitted intakes should have an attached submission pdf + # Once the take task has updated all entries and FYST-324 is complete, we can remove this @submission = current_intake.efile_submissions.find_by(id: params[:id]) error_redirect and return unless @submission.present? diff --git a/spec/controllers/state_file/questions/submission_pdfs_controller_spec.rb b/spec/controllers/state_file/questions/submission_pdfs_controller_spec.rb index 1da2789943..06aff57d59 100644 --- a/spec/controllers/state_file/questions/submission_pdfs_controller_spec.rb +++ b/spec/controllers/state_file/questions/submission_pdfs_controller_spec.rb @@ -48,6 +48,21 @@ expect(response).not_to have_http_status(:redirect) end end + + context "when an intake has a pregenerated pdf" do + # Pick a random PDF we have available and use it as a mock + let(:mock_file) { Rails.root.join('public', 'pdfs', 'AZ-140V.pdf') } + before do + az_intake.submission_pdf.attach(io: File.open(mock_file), filename: 'mock.pdf', content_type: 'application/pdf') + end + it "uses the pregenerated pdf" do + get :show, params: { id: efile_submission.id } + + tempfile = Tempfile.new(['output', '.pdf']) + tempfile.write(response.body.force_encoding("UTF-8")) + expect(tempfile.length).to equal File.size(mock_file) + end + end end end end \ No newline at end of file