Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM457-2126: Fix high risk calculation #1214

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/services/risk_assessment/high_risk_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

module RiskAssessment
class HighRiskAssessment
HIGH_RISK_THRESHOLD = 5000

def initialize(claim)
@claim = claim

@items = {
work_items: Nsm::CostSummary::WorkItems.new(@claim.work_items, @claim),
letters_calls: Nsm::CostSummary::LettersCalls.new(@claim),
disbursements: Nsm::CostSummary::Disbursements.new(@claim.disbursements.by_age, @claim)
}
@summary = Nsm::CheckAnswers::CostSummaryCard.new(claim)
end

def assess
high_cost? || counsel_assigned? || enhanced_rates_claimed? || extradition? || rep_order_withdrawn?
end

def high_cost?
@items.values.filter_map(&:total_cost).sum > 5000
profit_cost_summary = @summary.table_fields(formatted: false).find { _1[:name] == 'profit_costs' }
profit_cost_summary[:gross_cost] >= HIGH_RISK_THRESHOLD
end

def counsel_assigned?
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/work_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
uplift { '100' }
end

trait :high_profit_cost do
valid
work_type { WorkTypes::ATTENDANCE_WITHOUT_COUNSEL }
time_spent { 60_000 }
end

trait :medium_risk_values do
work_type { WorkTypes::PREPARATION }
time_spent { '100' }
Expand Down
17 changes: 14 additions & 3 deletions spec/services/risk_assessment/high_risk_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@
describe '#assess' do
subject(:assessment) { described_class.new(claim).assess }

let(:claim) { create(:claim, :one_work_item) }
let(:claim) { create(:claim, :one_work_item, :full_firm_details) }

it 'returns false when no clauses are triggered' do
expect(assessment).to be_falsey
end

context 'when cost is over £5000' do
before { create(:disbursement, :valid_high_cost, claim:) }
context 'when vat-inclusive profit-cost is £5000 or more' do
before do
create(:work_item, :high_profit_cost, claim:)
claim.reload
end

it 'returns true' do
expect(assessment).to be_truthy
end
end

context 'when non-profit-cost is over £5000' do
before { create(:disbursement, :valid_high_cost, claim:) }

it 'returns false' do
expect(assessment).to be_falsey
end
end

context 'when there is an assigned counsel' do
before { claim.assigned_counsel = 'yes' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe '#calculate' do
context 'returns high risk' do
let(:claim) { create(:claim, :with_assigned_council) }
let(:claim) { create(:claim, :with_assigned_council, :full_firm_details) }

it do
expect(described_class.calculate(claim)).to eq('high')
Expand All @@ -17,6 +17,7 @@
context 'returns medium risk' do
let(:claim) do
create(:claim,
:full_firm_details,
prosecution_evidence: 1,
defence_statement: 1,
number_of_witnesses: 1,
Expand Down Expand Up @@ -44,6 +45,7 @@
context 'returns low risk' do
let(:claim) do
create(:claim,
:full_firm_details,
prosecution_evidence: 50,
defence_statement: 1,
number_of_witnesses: 1,
Expand Down