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

Move update_document Feature Flag Logic #22345

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
55 changes: 29 additions & 26 deletions app/services/external_api/vbms_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,7 @@ def self.fetch_document_series_for(appeal)
end

def self.update_document_in_vbms(appeal, uploadable_document)
if FeatureToggle.enabled?(:use_ce_api)
file_update_payload = ClaimEvidenceFileUpdatePayload.new(
date_va_received_document: Time.current.strftime("%Y-%m-%d"),
document_type_id: uploadable_document.document_type_id,
file_content_path: uploadable_document.pdf_location,
file_content_source: uploadable_document.source
)

file_uuid = uploadable_document.document_series_reference_id.delete("{}")

VeteranFileUpdater.update_veteran_file(
veteran_file_number: appeal.veteran_file_number,
file_uuid: file_uuid,
file_update_payload: file_update_payload
)
else
@vbms_client ||= init_vbms_client
response = initialize_update(appeal, uploadable_document)
update_document(appeal.veteran_file_number, response.updated_document_token, uploadable_document.pdf_location)
end
update_document(appeal, uploadable_document)
end

def self.upload_document_to_vbms(appeal, uploadable_document)
Expand Down Expand Up @@ -148,13 +129,35 @@ def self.initialize_update(appeal, uploadable_document)
send_and_log_request(appeal.veteran_file_number, request)
end

def self.update_document(vbms_id, upload_token, filepath)
request = VBMS::Requests::UpdateDocument.new(
upload_token: upload_token,
filepath: filepath
)
send_and_log_request(vbms_id, request)
# rubocop:disable Metrics/MethodLength
def self.update_document(appeal, uploadable_document)
if FeatureToggle.enabled?(:use_ce_api)
file_update_payload = ClaimEvidenceFileUpdatePayload.new(
date_va_received_document: Time.current.strftime("%Y-%m-%d"),
document_type_id: uploadable_document.document_type_id,
file_content_path: uploadable_document.pdf_location,
file_content_source: uploadable_document.source,
subject: uploadable_document.document_subject.presence || uploadable_document.document_type
)

file_uuid = uploadable_document.document_series_reference_id.delete("{}")

VeteranFileUpdater.update_veteran_file(
veteran_file_number: appeal.veteran_file_number,
file_uuid: file_uuid,
file_update_payload: file_update_payload
)
else
@vbms_client ||= init_vbms_client
response = initialize_update(appeal, uploadable_document)
request = VBMS::Requests::UpdateDocument.new(
upload_token: response.updated_document_token,
filepath: uploadable_document.pdf_location
)
send_and_log_request(appeal.veteran_file_number, request)
end
end
# rubocop:enable Metrics/MethodLength

def self.clean_document(location)
File.delete(location)
Expand Down
7 changes: 2 additions & 5 deletions spec/services/external_api/vbms_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

let(:mock_file_update_payload) { instance_double(ClaimEvidenceFileUpdatePayload) }

it "calls the CE API" do

Check failure on line 100 in spec/services/external_api/vbms_service_spec.rb

View workflow job for this annotation

GitHub Actions / caseflow_rspec_job (12, 10)

ExternalApi::VBMSService.update_document_in_vbms with use_ce_api feature toggle enabled calls the CE API Failure/Error: subject: uploadable_document.document_subject.presence || uploadable_document.document_type #<InstanceDouble(UpdateDocumentInVbms) (anonymous)> received unexpected message :document_subject with (no args)
expect(ClaimEvidenceFileUpdatePayload).to receive(:new).and_return(mock_file_update_payload)
expect(VeteranFileUpdater)
.to receive(:update_veteran_file)
Expand All @@ -118,11 +118,8 @@
expect(FeatureToggle).to receive(:enabled?).with(:use_ce_api).and_return(false)
expect(described).to receive(:init_vbms_client)
expect(described).to receive(:initialize_update).and_return(mock_init_update_response)
expect(described).to receive(:update_document).with(
appeal.veteran_file_number,
"document-token",
"/path/to/test/location"
)
expect(described).to receive(:send_and_log_request)
.with(appeal.veteran_file_number, instance_of(VBMS::Requests::UpdateDocument))

described.update_document_in_vbms(appeal, fake_document)
end
Expand Down
Loading