diff --git a/app/controllers/appeals_controller.rb b/app/controllers/appeals_controller.rb index 9813c971005..6e4c61a4241 100644 --- a/app/controllers/appeals_controller.rb +++ b/app/controllers/appeals_controller.rb @@ -92,6 +92,18 @@ def document_count handle_non_critical_error("document_count", error) end + # series_id is lowercase, no curly braces because it comes from url + def document_lookup + series_id = "{#{params[:series_id]}}".upcase + document = Document.find_by(series_id: series_id, file_number: appeal.veteran_file_number) + + unless document + document = VBMSService.fetch_document_series_for(appeal).map(&:series_id).include?(series_id) + end + + render json: { document_presence: document.present? } + end + def power_of_attorney render json: power_of_attorney_data end @@ -395,4 +407,3 @@ def get_appeal_object(appeals_id) end end end - diff --git a/client/app/styles/_commons.scss b/client/app/styles/_commons.scss index 73ac3e8096b..295967b8a57 100644 --- a/client/app/styles/_commons.scss +++ b/client/app/styles/_commons.scss @@ -483,7 +483,7 @@ svg title { .cf-form-textarea { color: $color-gray-dark; - + textarea { max-height: 120px; } diff --git a/config/routes.rb b/config/routes.rb index 81670f08808..297e72701a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -158,6 +158,8 @@ end match '/appeals/:appeal_id/edit/:any' => 'appeals#edit', via: [:get] + get '/appeals/:appeal_id/document/:series_id' => 'appeals#document_lookup' + get '/appeals/:appeals_id/notifications' => 'appeals#fetch_notification_list' get '/task_tree/:appeal_type/:appeal_id' => 'task_tree#show' diff --git a/lib/fakes/vbms_service.rb b/lib/fakes/vbms_service.rb index bde1e02782b..32ec5f77481 100644 --- a/lib/fakes/vbms_service.rb +++ b/lib/fakes/vbms_service.rb @@ -93,11 +93,11 @@ def self.fetch_documents_for(appeal, _user = nil) end def self.fetch_document_series_for(appeal) - Document.where(file_number: appeal.veteran_file_number).map do |document| + Document.where(file_number: appeal.veteran_file_number).flat_map do |document| (0..document.id % 3).map do |index| OpenStruct.new( document_id: "#{document.vbms_document_id}#{(index > 0) ? index : ''}", - series_id: "TEST_SERIES_#{document.id}", + series_id: "{TEST_SERIES_#{document.id}}", version: index + 1, received_at: document.received_at ) diff --git a/spec/controllers/appeals_controller_spec.rb b/spec/controllers/appeals_controller_spec.rb index 616680c5549..f4d7bc99eca 100644 --- a/spec/controllers/appeals_controller_spec.rb +++ b/spec/controllers/appeals_controller_spec.rb @@ -342,6 +342,89 @@ end end + describe "GET appeals/:appeal_id/document/:series_id" do + let(:series_id) { SecureRandom.uuid } + let(:document) { create(:document) } + + before do + User.authenticate!(roles: ["System Admin"]) + end + + def allow_vbms_to_return_doc + allow(VBMSService) + .to receive(:fetch_document_series_for) + .with(appeal) + .and_return([OpenStruct.new(series_id: "{#{series_id.upcase}}")]) + end + + def allow_vbms_to_return_empty_array + allow(VBMSService) + .to receive(:fetch_document_series_for) + .with(appeal) + .and_return([]) + end + + shared_examples "document present" do + it "returns true in the JSON" do + get :document_lookup, params: { appeal_id: appeal.external_id, series_id: series_id } + response_body = JSON.parse(response.body) + expect(response_body["document_presence"]).to eq(true) + end + end + + shared_examples "document not present" do + it "returns false in the JSON" do + get :document_lookup, params: { appeal_id: appeal.external_id, series_id: series_id } + response_body = JSON.parse(response.body) + expect(response_body["document_presence"]).to eq(false) + end + end + + context "Appeal" do + let(:appeal) { create(:appeal) } + context "when document exists in the documents table" do + let!(:document) do + create(:document, + series_id: "{#{series_id.upcase}}", + file_number: appeal.veteran_file_number) + end + include_examples "document present" + end + + context "when document exists in VBMS" do + before { allow_vbms_to_return_doc } + include_examples "document present" + end + + context "when document does not exist" do + before { allow_vbms_to_return_empty_array } + include_examples "document not present" + end + end + + context "LegacyAppeal" do + let(:appeal) { create(:legacy_appeal, vacols_case: create(:case, bfcorlid: "0000000000S")) } + context "when document exists in the documents table" do + let!(:document) do + create(:document, + series_id: "{#{series_id.upcase}}", + file_number: appeal.veteran_file_number) + end + include_examples "document present" + end + + context "when document exists in VBMS" do + before { allow_vbms_to_return_doc } + include_examples "document present" + end + + context "when document does not exist" do + before { allow_vbms_to_return_empty_array } + include_examples "document not present" + end + end + end + describe "GET cases/:id" do context "Legacy Appeal" do let(:the_case) { create(:case) }