Skip to content

Commit

Permalink
FYST-327 (#4684)
Browse files Browse the repository at this point in the history
* Using pregenerated pdf
* Added spec to cover pre-generated pdf
  • Loading branch information
tofarr authored Aug 8, 2024
1 parent 0b8e00f commit 9a8510d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9a8510d

Please sign in to comment.