Skip to content

Commit

Permalink
Add method to group claims by provider for claim activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kizr committed Jan 31, 2025
1 parent 5ed56bb commit 9da9ac1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/claims/claim_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ class Claims::ClaimActivity < ApplicationRecord
PAYMENT_AND_CLAWBACK_ACTIONS = %w[payment_request_delivered clawback_request_delivered clawback_response_uploaded].freeze
SAMPLING_ACTIONS = %w[sampling_uploaded sampling_response_uploaded].freeze
MANUAL_ACTIONS = %w[provider_approved_audit rejected_by_provider rejected_by_school clawback_requested rejected_by_payer paid_by_payer information_sent_to_payer].freeze

def claims_by_provider
return {} unless record.respond_to?(:claims)

record.claims.group_by(&:provider)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<h2 class="govuk-heading-m"><%= t(".providers") %></h2>

<% claim_activity.record.claims.group_by(&:provider).each do |provider, provider_claims| %>
<% claim_activity.claims_by_provider.each do |provider, provider_claims| %>
<h3 class="govuk-heading-s"><%= provider.name %></h3>

<%= govuk_table do |table| %>
Expand Down
29 changes: 29 additions & 0 deletions spec/models/claims/claim_activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,33 @@
describe "delegations" do
it { is_expected.to delegate_method(:full_name).to(:user).with_prefix(true).allow_nil }
end

describe "#claims_by_provider" do
context "when the record responds to claims" do
let(:provider) { build(:claims_provider) }
let(:claim_1) { build(:claim, provider: provider) }
let(:claim_2) { build(:claim, provider: provider) }
let(:provider_sampling) { build(:provider_sampling, provider:) }
let(:claim_activity) { create(:claim_activity, action: :sampling_uploaded, record: provider_sampling) }

before do
create(:claims_provider_sampling_claim, claim: claim_1, provider_sampling: provider_sampling)
create(:claims_provider_sampling_claim, claim: claim_2, provider_sampling: provider_sampling)
end

it "returns the claims grouped by provider" do
expect(claim_activity.claims_by_provider).to eq({
provider => [claim_1, claim_2],
})
end
end

context "when the record does not respond to claims" do
it "returns an empty array" do
claim_activity = create(:claim_activity, action: :sampling_uploaded, record: create(:claim))

expect(claim_activity.claims_by_provider).to eq({})
end
end
end
end

0 comments on commit 9da9ac1

Please sign in to comment.