Skip to content

Commit

Permalink
Only prevent ramp refilings if all ramp elections are still pending (#…
Browse files Browse the repository at this point in the history
…7257)

this is because a veteran can have multiple ramp elections at the same time,
which is something that has not always been the case.

connects #7240
  • Loading branch information
shanear authored and va-bot committed Oct 5, 2018
1 parent d8c25a7 commit 072065d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 19 deletions.
8 changes: 6 additions & 2 deletions app/models/ramp_refiling_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def ui_hash(ama_enabled)
receipt_date: detail.receipt_date,
election_receipt_date: detail.election_receipt_date,
appeal_docket: detail.appeal_docket,
issues: ramp_elections.map(&:issues).flatten.map(&:ui_hash),
issues: ramp_elections_with_decisions.map(&:issues).flatten.map(&:ui_hash),
end_product_description: detail.end_product_description
)
end
Expand All @@ -74,7 +74,7 @@ def create_end_product_and_contentions
def validate_detail_on_start
if ramp_elections.empty?
self.error_code = :no_complete_ramp_election
elsif ramp_elections.any?(&:end_product_active?)
elsif ramp_elections.all?(&:end_product_active?)
self.error_code = :ramp_election_is_active
elsif ramp_elections.all? { |election| election.issues.empty? }
self.error_code = :ramp_election_no_issues
Expand Down Expand Up @@ -102,4 +102,8 @@ def initial_ramp_refiling
def ramp_elections
RampElection.established.where(veteran_file_number: veteran_file_number).all
end

def ramp_elections_with_decisions
ramp_elections.reject(&:end_product_active?)
end
end
104 changes: 87 additions & 17 deletions spec/models/ramp_refiling_intake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,28 @@
)
end

let(:completed_ramp_election_ep) do
Generators::EndProduct.build(
veteran_file_number: veteran_file_number,
bgs_attrs: { status_type_code: "CLR" }
)
end

let(:completed_ramp_election) do
re = create(:ramp_election,
veteran_file_number: veteran_file_number,
notice_date: 4.days.ago,
receipt_date: 3.days.ago,
established_at: Time.zone.now)
ep = Generators::EndProduct.build(
veteran_file_number: veteran_file_number,
bgs_attrs: { status_type_code: "CLR" }
)

EndProductEstablishment.create(
source: re,
established_at: Time.zone.now,
veteran_file_number: veteran_file_number,
reference_id: ep.claim_id,
reference_id: completed_ramp_election_ep.claim_id,
synced_status: "CLR"
)

re
end

Expand Down Expand Up @@ -67,6 +72,65 @@
[Generators::Contention.build(claim_id: claim_id, text: "Left knee")]
end

context "#ui_hash" do
subject { intake.ui_hash(true) }

let!(:ramp_election) do
completed_ramp_election
end

let!(:ramp_election_contentions) do
[Generators::Contention.build(claim_id: completed_ramp_election_ep.claim_id, text: "Left knee")]
end

let!(:pending_ramp_election) do
create(:ramp_election,
veteran_file_number: veteran_file_number,
notice_date: 4.days.ago,
established_at: Time.zone.now)
end

let!(:pending_ramp_election_contentions) do
[Generators::Contention.build(claim_id: pending_end_product.claim_id, text: "Not me!")]
end

let!(:pending_end_product) do
Generators::EndProduct.build(
veteran_file_number: veteran_file_number,
bgs_attrs: { status_type_code: "PEND" }
)
end

let!(:pending_end_product_establishment) do
create(
:end_product_establishment,
veteran_file_number: veteran_file_number,
source: pending_ramp_election,
reference_id: pending_end_product.claim_id,
established_at: Time.zone.now,
synced_status: "PEND"
)
end

let(:detail) do
RampRefiling.create!(
veteran_file_number: veteran_file_number,
receipt_date: 10.seconds.ago,
option_selected: "supplemental_claim"
)
end

before do
ramp_election.recreate_issues_from_contentions!
pending_ramp_election.recreate_issues_from_contentions!
end

it "only returns issues for RAMP elections with completed decisions" do
expect(subject[:issues].count).to eq(1)
expect(subject[:issues].first[:description]).to eq("Left knee")
end
end

context "#start!" do
subject { intake.start! }

Expand Down Expand Up @@ -153,15 +217,13 @@
end

context "the EP associated with original RampElection is still pending" do
let(:end_product_status) { "PEND" }

let!(:end_product_establishment) do
create(
:end_product_establishment,
veteran_file_number: veteran_file_number,
source: ramp_election,
established_at: Time.zone.now,
synced_status: end_product_status
synced_status: "PEND"
)
end

Expand Down Expand Up @@ -203,6 +265,23 @@
)
end

let!(:pending_ramp_election) do
create(:ramp_election,
veteran_file_number: veteran_file_number,
notice_date: 4.days.ago,
established_at: Time.zone.now)
end

let!(:pending_end_product_establishment) do
create(
:end_product_establishment,
veteran_file_number: veteran_file_number,
source: pending_ramp_election,
established_at: Time.zone.now,
synced_status: "PEND"
)
end

before { ramp_election.recreate_issues_from_contentions! }

it { is_expected.to eq(true) }
Expand Down Expand Up @@ -246,15 +325,6 @@
let(:claim_id1) { EndProductEstablishment.find_by(source: ramp_election1).reference_id }
let(:claim_id2) { EndProductEstablishment.find_by(source: ramp_election2).reference_id }

context "the EP associated with original RampElection is still pending" do
let(:end_product_status) { "PEND" }

it "adds ramp_election_is_active and returns false" do
expect(subject).to eq(false)
expect(intake.error_code).to eq("ramp_election_is_active")
end
end

context "the EP associated with original RampElection is closed" do
context "there are no contentions on the EP" do
it "adds ramp_election_no_issues and returns false" do
Expand Down

0 comments on commit 072065d

Please sign in to comment.