Skip to content

Commit

Permalink
CRM457-2126: Fix high risk calculation (#1214)
Browse files Browse the repository at this point in the history
## Description of change
It was 'all costs, excluding VAT, are greater than 5000'.
It is now 'profit costs, including VAT, are greater than or equal to
5000'

[Link to relevant
ticket](https://dsdmoj.atlassian.net/browse/CRM457-2126)
  • Loading branch information
patrick-laa authored Oct 9, 2024
1 parent cac2df9 commit fd1a060
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
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
4 changes: 3 additions & 1 deletion spec/services/risk_assessment/risk_assessment_scorer_spec.rb
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

0 comments on commit fd1a060

Please sign in to comment.