Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix LH Veteran-Uploaded evidence filenames #19469

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions app/sidekiq/evss/disability_compensation_form/submit_uploads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.api_upload_provider(submission, document_type, supporting_evidence_atta
# Recursively submits a file in a new instance of this job for each upload in the uploads list
#
# @param submission_id [Integer] The {Form526Submission} id
# @param upload_data [String] upload GUID in AWS S3
# @param upload_data [String] Form metadata for attachment, including upload GUID in AWS S3
#
def perform(submission_id, upload_data)
Sentry.set_tags(source: '526EZ-all-claims')
Expand All @@ -124,7 +124,7 @@ def perform(submission_id, upload_data)
raise Common::Exceptions::ValidationErrors, document_data unless document_data.valid?

if Flipper.enabled?(:disability_compensation_use_api_provider_for_submit_veteran_upload)
upload_via_api_provider(submission, upload_data['attachmentId'], file_body, sea)
upload_via_api_provider(submission, upload_data, file_body, sea)
else
EVSS::DocumentsService.new(submission.auth_headers).upload(file_body, document_data)
end
Expand All @@ -141,13 +141,17 @@ def perform(submission_id, upload_data)
# We use these providers to iteratively migrate uploads to Lighthouse
#
# @param submission [Form526Submission]
# @document_type [string] VA internal document code for attachment type (e.g. L451)
# @file_body [string] Attachment file contents
# @attachment [SupportingEvidenceAttachment] Upload attachment record
def upload_via_api_provider(submission, document_type, file_body, attachment)
# @param upload_data [Hash] the form metadata for the attachment
# @param file_body [string] Attachment file contents
# @param attachment [SupportingEvidenceAttachment] Upload attachment record
def upload_via_api_provider(submission, upload_data, file_body, attachment)
document_type = upload_data['attachmentId']
provider = self.class.api_upload_provider(submission, document_type, attachment)

upload_document = provider.generate_upload_document(attachment.converted_filename)
# Fall back to name in metadata if converted_filename returns nil; matches existing behavior
filename = attachment.converted_filename || upload_data['name']

upload_document = provider.generate_upload_document(filename)
provider.submit_upload_document(upload_document, file_body)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
claim_id: submission.submitted_claim_id,
participant_id: user.participant_id,
document_type: upload_data.first['attachmentId'],
file_name: attachment.converted_filename,
file_name: upload_data.first['name'],
supporting_evidence_attachment: attachment
)
end
Expand Down Expand Up @@ -231,6 +231,32 @@
expect(Lighthouse526DocumentUpload.where(**upload_attributes).count).to eq(1)
end

# This is a possibility accounted for in the existing EVSS submission code.
# The original attachment object does not have a converted_filename.
context 'when the SupportingEvidenceAttachment returns a converted_filename' do
before do
attachment.update!(file_data: JSON.parse(attachment.file_data)
.merge('converted_filename' => 'converted_filename.pdf').to_json)
end

let(:expected_lighthouse_document_with_converted_file_name) do
LighthouseDocument.new(
claim_id: submission.submitted_claim_id,
participant_id: user.participant_id,
document_type: upload_data.first['attachmentId'],
file_name: 'converted_filename.pdf',
supporting_evidence_attachment: attachment
)
end

it 'uses the converted_filename instead of the metadata in upload_data["name"]' do
expect(BenefitsDocuments::Form526::UploadSupplementalDocumentService).to receive(:call)
.with(file.read, expected_lighthouse_document_with_converted_file_name)

perform_upload
end
end

context 'when Lighthouse returns an error response' do
let(:error_response_body) do
# From vcr_cassettes/lighthouse/benefits_claims/documents/lighthouse_form_526_document_upload_400.yml
Expand Down Expand Up @@ -292,7 +318,7 @@
EVSSClaimDocument.new(
evss_claim_id: submission.submitted_claim_id,
document_type: upload_data.first['attachmentId'],
file_name: attachment.converted_filename
file_name: upload_data.first['name']
)
end

Expand Down
Loading