diff --git a/app/sidekiq/evss/disability_compensation_form/submit_uploads.rb b/app/sidekiq/evss/disability_compensation_form/submit_uploads.rb index b304d54670f..58a4bf6ecfe 100644 --- a/app/sidekiq/evss/disability_compensation_form/submit_uploads.rb +++ b/app/sidekiq/evss/disability_compensation_form/submit_uploads.rb @@ -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') @@ -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 @@ -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 diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb index 95108d52873..8434fd2acf9 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb @@ -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 @@ -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 @@ -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