Skip to content

Commit

Permalink
Merge pull request #19141 from department-of-veterans-affairs/msteele…
Browse files Browse the repository at this point in the history
…/APPEALS-25277

msteele/APPEALS-25277
  • Loading branch information
ThorntonMatthew authored Aug 10, 2023
2 parents f7bd235 + 00406c0 commit 47fccaa
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/controllers/appeals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -395,4 +407,3 @@ def get_appeal_object(appeals_id)
end
end
end

2 changes: 1 addition & 1 deletion client/app/styles/_commons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ svg title {

.cf-form-textarea {
color: $color-gray-dark;

textarea {
max-height: 120px;
}
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions lib/fakes/vbms_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
83 changes: 83 additions & 0 deletions spec/controllers/appeals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 47fccaa

Please sign in to comment.