Skip to content

Commit

Permalink
Move update_document Feature Flag Logic (#22345)
Browse files Browse the repository at this point in the history
* Move update_document Feature Flag Logic

Move to wrap call to the legacy SOAP request. Previously, the
legacy request could still be used if users called update_document
directly, but this PR closes that loophole.

* Add Subject to Doc Update
  • Loading branch information
tradesmanhelix authored Jul 30, 2024
1 parent 158d342 commit a876c4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
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 @@ -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

0 comments on commit a876c4e

Please sign in to comment.