Skip to content

Commit

Permalink
New provisional assessment report
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmhaig committed Jul 11, 2023
1 parent c237015 commit 3650c42
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/services/reports/provisional_assessments_new.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Reports
class ProvisionalAssessmentsNew
COLUMNS = %w[
supplier_name
total
assessed
disallowed
bill_type
case_type
earliest_representation_order_date
case_worker
maat_number
].freeze
INCLUDES = [
:case_type,
:determinations,
:case_workers,
{
external_user: :provider,
defendants: :representation_orders
}
].freeze

def self.call = new.call

def call
Claim::BaseClaim.includes(INCLUDES)
.where(state: %w[authorised part_authorised])
.map { |claim| format_row(claim) }.to_a
end

private

def format_row(claim)
total = claim.total_including_vat
assessed = claim.amount_assessed
[
claim.provider.name, total, assessed, total - assessed,
'TBD - Bill type',
claim.case_type.name,
claim.earliest_representation_order_date,
claim.case_workers.last.name,
claim.defendants.last.representation_orders.last.maat_reference
]
end
end
end
74 changes: 74 additions & 0 deletions spec/services/reports/provisional_assessments_new_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require 'rails_helper'

RSpec.shared_examples 'data for an MI report' do
it { expect(described_class::COLUMNS).to be_an(Array) }
it { expect(described_class.call).to be_an(Array) }
it { expect(described_class.new.call).to be_an(Array) }
end

RSpec.describe Reports::ProvisionalAssessmentsNew do
subject(:report) { described_class.new }

it_behaves_like 'data for an MI report'

describe '#call' do
subject(:call) { described_class.call }

context 'with a single draft claim' do
before { create(:claim, :draft) }

it { is_expected.to be_empty }
end

context 'with a single submitted claim' do
before { create(:claim, :submitted) }

it { is_expected.to be_empty }
end

context 'with a single allocated claim' do
before { create(:claim, :allocated) }

it { is_expected.to be_empty }
end

context 'with a single rejected claim' do
before { create(:claim, :rejected) }

it { is_expected.to be_empty }
end

context 'with a single redetermination claim' do
before { create(:claim, :redetermination) }

it { is_expected.to be_empty }
end

context 'with a single authorised claim' do
before { create(:claim, :authorised) }

it { expect(call.length).to eq(1) }
end

context 'with a single part_authorised claim' do
let!(:claim) do
create(
:claim, :part_authorised,
external_user:
)
end
let(:external_user) { build(:external_user, provider: build(:provider, name: 'Test provider')) }

it { expect(call.length).to eq(1) }
it { expect(call.first[0]).to eq('Test provider') }
it { expect(call.first[1]).to eq(claim.total_including_vat) }
it { expect(call.first[2]).to eq(claim.amount_assessed) }
it { expect(call.first[3]).to eq(claim.total_including_vat - claim.amount_assessed) }
# it { expect(call.first[4]).to eq(Bill type) }
it { expect(call.first[5]).to eq(claim.case_type.name) }
it { expect(call.first[6]).to eq(claim.earliest_representation_order_date) }
it { expect(call.first[7]).to eq(claim.case_workers.last.name) }
it { expect(call.first[8]).to eq(claim.defendants.last.representation_orders.last.maat_reference) }
end
end
end

0 comments on commit 3650c42

Please sign in to comment.