-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add New CE REST API REST Functionality for Vet Docs (#21812)
* Add New CE REST API REST Functionality for Vet Docs - Add feature toggle to enable/disable new functionality. - Call REST endpoint for veteran docs when the use_ce_api feature toggle is enabled. - Add supporting services and specs. * Fix Misc. Issues - Update JsonApiResponseAdapter with latest changes to respnse parsing found in caseflow-efolder testing. - Update ruby_claim_evidence_api to bugfix version. * Update received_at Date Parsing Logic - Use slashes instead of hyphens to help JS correctly parse the date. * Fix Double Quote Issue * Improve JsonApiResponseAdapter Blank Response Handling * Pass Rails Logger to VeteranFileFetcher
- Loading branch information
1 parent
6dc18ec
commit 59de8ea
Showing
8 changed files
with
265 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
# Translates JSON API responses into a format that's compatible with the legacy SOAP responses expected | ||
# by most of Caseflow | ||
class JsonApiResponseAdapter | ||
def adapt_fetch_document_series_for(json_response) | ||
documents = [] | ||
|
||
return documents unless valid_json_response?(json_response) | ||
|
||
json_response.body["files"].each do |file_resp| | ||
documents.push(fetch_document_series_for_response(file_resp)) | ||
end | ||
|
||
documents | ||
end | ||
|
||
private | ||
|
||
def valid_json_response?(json_response) | ||
return false if json_response&.body.blank? | ||
|
||
json_response.body.key?("files") | ||
end | ||
|
||
def fetch_document_series_for_response(file_json) | ||
system_data = file_json["currentVersion"]["systemData"] | ||
provider_data = file_json["currentVersion"]["providerData"] | ||
|
||
OpenStruct.new( | ||
document_id: "{#{file_json['currentVersionUuid'].upcase}}", | ||
series_id: "{#{file_json['uuid'].upcase}}", | ||
version: "1", | ||
type_description: provider_data["subject"], | ||
type_id: provider_data["documentTypeId"], | ||
doc_type: provider_data["documentTypeId"], | ||
subject: provider_data["subject"], | ||
# gsub here so that JS will correctly handle this date | ||
# (with dashes the date is 1 day off due to UTC issues) | ||
received_at: provider_data["dateVaReceivedDocument"]&.gsub("-", "/"), | ||
source: provider_data["contentSource"], | ||
mime_type: system_data["mimeType"], | ||
alt_doc_types: nil, | ||
restricted: nil, | ||
upload_date: system_data["uploadedDateTime"] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
VeteranFileFetcher = ExternalApi::VeteranFileFetcher | ||
.new(use_canned_api_responses: ApplicationController.dependencies_faked?, logger: Rails.logger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
describe ExternalApi::VBMSService do | ||
subject(:described) { described_class } | ||
|
||
describe ".fetch_document_series_for" do | ||
let(:mock_json_adapter) { instance_double(JsonApiResponseAdapter) } | ||
let(:mock_vbms_document_series_for_appeal) { instance_double(ExternalApi::VbmsDocumentSeriesForAppeal) } | ||
|
||
let!(:appeal) { create(:appeal) } | ||
|
||
before do | ||
allow(JsonApiResponseAdapter).to receive(:new).and_return(mock_json_adapter) | ||
allow(ExternalApi::VbmsDocumentSeriesForAppeal).to receive(:new).and_return(mock_vbms_document_series_for_appeal) | ||
end | ||
|
||
context "with use_ce_api feature toggle enabled" do | ||
before { FeatureToggle.enable!(:use_ce_api) } | ||
after { FeatureToggle.disable!(:use_ce_api) } | ||
|
||
it "calls the CE API" do | ||
expect(VeteranFileFetcher).to receive(:fetch_veteran_file_list) | ||
.with(veteran_file_number: appeal.veteran_file_number) | ||
expect(mock_json_adapter).to receive(:adapt_fetch_document_series_for).and_return([]) | ||
|
||
described.fetch_document_series_for(appeal) | ||
end | ||
end | ||
|
||
context "with no feature toggles enabled" do | ||
it "calls the VbmsDocumentSeriesForAppeal service" do | ||
expect(FeatureToggle).to receive(:enabled?).with(:use_ce_api).and_return(false) | ||
expect(ExternalApi::VbmsDocumentSeriesForAppeal).to receive(:new).with(file_number: appeal.veteran_file_number) | ||
expect(mock_vbms_document_series_for_appeal).to receive(:fetch) | ||
|
||
described.fetch_document_series_for(appeal) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
describe JsonApiResponseAdapter do | ||
subject(:described) { described_class.new } | ||
|
||
let(:api_response) { instance_double(ExternalApi::Response) } | ||
|
||
describe "#adapt_fetch_document_series_for" do | ||
context "with invalid responses" do | ||
it "handles blank responses" do | ||
parsed = described.adapt_fetch_document_series_for(nil) | ||
|
||
expect(parsed.length).to eq 0 | ||
end | ||
|
||
it "handles blank response bodies" do | ||
response = instance_double(ExternalApi::Response, body: nil) | ||
parsed = described.adapt_fetch_document_series_for(response) | ||
|
||
expect(parsed.length).to eq 0 | ||
end | ||
|
||
it "handles response bodies with no files" do | ||
response = instance_double(ExternalApi::Response, body: {}) | ||
parsed = described.adapt_fetch_document_series_for(response) | ||
|
||
expect(parsed.length).to eq 0 | ||
end | ||
end | ||
|
||
it "correctly parses an API response" do | ||
file = File.open(Rails.root.join("spec/support/api_responses/ce_api_folders_files_search.json")) | ||
data_hash = JSON.parse(File.read(file)) | ||
file.close | ||
|
||
expect(api_response).to receive(:body) | ||
.exactly(3).times.and_return(data_hash) | ||
|
||
parsed = described.adapt_fetch_document_series_for(api_response) | ||
|
||
expect(parsed.length).to eq 2 | ||
|
||
expect(parsed[0].document_id).to eq "{03223945-468B-4E8A-B79B-82FA73C2D2D9}" | ||
expect(parsed[0].received_at).to eq "2018/03/08" | ||
expect(parsed[0].mime_type).to eq "application/pdf" | ||
|
||
expect(parsed[1].document_id).to eq "{7D6AFD8C-3BF7-4224-93AE-E1F07AC43C71}" | ||
expect(parsed[1].received_at).to eq "2018/12/08" | ||
expect(parsed[1].mime_type).to eq "application/pdf" | ||
end | ||
end | ||
end |
84 changes: 84 additions & 0 deletions
84
spec/support/api_responses/ce_api_folders_files_search.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"page": { | ||
"totalPages": 1, | ||
"requestedResultsPerPage": 20, | ||
"currentPage": 1, | ||
"totalResults": 2 | ||
}, | ||
"files": [ | ||
{ | ||
"owner": { | ||
"type": "VETERAN", | ||
"id": "123456789" | ||
}, | ||
"uuid": "23e7ae3b-5489-4fa9-b6e3-b1f953287138", | ||
"currentVersionUuid": "03223945-468b-4e8a-b79b-82fa73c2d2d9", | ||
"currentVersion": { | ||
"systemData": { | ||
"uploadedDateTime": "2018-03-08T14:21:40", | ||
"contentName": "20180308091849 - codesheet.pdf", | ||
"mimeType": "application/pdf", | ||
"uploadSource": "RATING" | ||
}, | ||
"providerData": { | ||
"subject": "Rating Decision - Codesheet", | ||
"documentTypeId": 338, | ||
"ocrStatus": "Failure to Process", | ||
"newMail": false, | ||
"bookmarks": { | ||
"VBA": { | ||
"isDefaultRealm": true | ||
} | ||
}, | ||
"systemSource": "RATING", | ||
"isAnnotated": false, | ||
"modifiedDateTime": "2018-03-08T14:21:40", | ||
"numberOfContentions": 0, | ||
"readByCurrentUser": false, | ||
"dateVaReceivedDocument": "2018-03-08", | ||
"hasContentionAnnotations": false, | ||
"contentSource": "VBMS-R", | ||
"actionable": false, | ||
"lastOpenedDocument": false | ||
} | ||
} | ||
}, | ||
{ | ||
"owner": { | ||
"type": "VETERAN", | ||
"id": "123456789" | ||
}, | ||
"uuid": "a001424d-99f9-4a96-977d-ee06ec4ef3a7", | ||
"currentVersionUuid": "7d6afd8c-3bf7-4224-93ae-e1f07ac43c71", | ||
"currentVersion": { | ||
"systemData": { | ||
"uploadedDateTime": "2018-03-08T14:21:43", | ||
"contentName": "20180308091852 - narrative.pdf", | ||
"mimeType": "application/pdf", | ||
"uploadSource": "RATING" | ||
}, | ||
"providerData": { | ||
"subject": "Rating Decision - Narrative", | ||
"documentTypeId": 339, | ||
"ocrStatus": "Failure to Process", | ||
"newMail": false, | ||
"bookmarks": { | ||
"VBA": { | ||
"isDefaultRealm": true | ||
} | ||
}, | ||
"systemSource": "RATING", | ||
"isAnnotated": false, | ||
"modifiedDateTime": "2018-03-08T14:21:43", | ||
"numberOfContentions": 0, | ||
"readByCurrentUser": false, | ||
"dateVaReceivedDocument": "2018-12-08", | ||
"hasContentionAnnotations": false, | ||
"contentSource": "VBMS-R", | ||
"actionable": false, | ||
"lastOpenedDocument": false | ||
} | ||
} | ||
} | ||
] | ||
} |