Skip to content

Commit

Permalink
Merge pull request #3302 from DFE-Digital/quality-assured-filters
Browse files Browse the repository at this point in the history
[CAPT-1401] Quality assured filters
  • Loading branch information
asmega authored Oct 16, 2024
2 parents f3e58d7 + 864512e commit 2d0e251
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 19 deletions.
53 changes: 38 additions & 15 deletions app/forms/admin/claims_filter_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def claims
approved_awaiting_payroll
when "automatically_approved"
Claim.current_academic_year.auto_approved
when "quality_assured"
Claim
.current_academic_year
.where.not(qa_completed_at: nil)
when "quality_assured_approved"
Claim
.current_academic_year
.where.not(qa_completed_at: nil)
.approved
when "quality_assured_rejected"
Claim
.current_academic_year
.where.not(qa_completed_at: nil)
.rejected
when "automatically_approved_awaiting_payroll"
Claim.current_academic_year.payrollable.auto_approved
when "rejected"
Expand Down Expand Up @@ -88,21 +102,30 @@ def policy_select_options
end
end

def status_select_options
[
["Awaiting decision - not on hold", nil],
["Awaiting provider verification", "awaiting_provider_verification"],
["Awaiting decision - on hold", "held"],
["Awaiting decision - failed bank details", "failed_bank_validation"],
["Approved awaiting QA", "approved_awaiting_qa"],
["Approved awaiting payroll", "approved_awaiting_payroll"],
["Automatically approved", "automatically_approved"],
["Automatically approved awaiting payroll", "automatically_approved_awaiting_payroll"],
["Approved", "approved"],
["Rejected", "rejected"]
].map do |name, id|
OpenStruct.new(id:, name:)
end
def status_grouped_select_options
{
"Awaiting" => {
"Awaiting decision - not on hold" => nil,
"Awaiting provider verification" => "awaiting_provider_verification",
"Awaiting decision - on hold" => "held",
"Awaiting decision - failed bank details" => "failed_bank_validation"
},
"QA" => {
"Approved awaiting QA" => "approved_awaiting_qa",
"Quality assured" => "quality_assured",
"Quality assured - approved" => "quality_assured_approved",
"Quality assured - rejected" => "quality_assured_rejected"
},
"Payroll" => {
"Approved awaiting payroll" => "approved_awaiting_payroll",
"Automatically approved awaiting payroll" => "automatically_approved_awaiting_payroll"
},
"Decisioned" => {
"Automatically approved" => "automatically_approved",
"Approved" => "approved",
"Rejected" => "rejected"
}
}
end

def team_member_select_options
Expand Down
12 changes: 11 additions & 1 deletion app/views/admin/claims/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@
</div>

<div>
<%= f.govuk_collection_select :status, @filter_form.status_select_options, :id, :name %>
<%= f.govuk_select(:status, label: { text: "Status" }) do %>
<% @filter_form.status_grouped_select_options.each do |group_name, menu_items| %>
<optgroup label="<%= group_name %>">
<% menu_items.each do |name, value| %>
<option value="<%= value %>" <%= "selected" if @filter_form.status == value %>>
<%= name %>
</option>
<% end %>
</optgroup>
<% end %>
<% end %>
</div>

<div>
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
started_at { Time.zone.now }
reference { Reference.new.to_s }

trait :current_academic_year do
academic_year { AcademicYear.current }
end

transient do
policy { Policies::StudentLoans }
eligibility_factory { :"#{policy.to_s.underscore}_eligibility" }
Expand Down
41 changes: 38 additions & 3 deletions spec/forms/admin/claims_filter_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

RSpec.describe Admin::ClaimsFilterForm, type: :model do
describe "#claims" do
let(:session) { {} }
let(:filters) { {} }

subject { described_class.new(filters:, session:) }

context "when rejected whilst awaiting provider verification" do
let!(:claim) do
create(
Expand All @@ -12,11 +17,8 @@
)
end

let(:session) { {} }
let(:filters) { {status: "awaiting_provider_verification"} }

subject { described_class.new(filters:, session:) }

it "filtering by status awaiting provider verification excludes them" do
expect(subject.claims).not_to include(claim)
end
Expand Down Expand Up @@ -96,5 +98,38 @@
expect(subject.claims.count).to eql(1)
end
end

context "filtering for quality_assured" do
let!(:qa_approved_claim) { create(:claim, :approved, :qa_completed, :current_academic_year) }
let!(:qa_rejected_claim) { create(:claim, :rejected, :qa_completed, :current_academic_year) }

let(:filters) { {status: "quality_assured"} }

it "returns all quality assured claims" do
expect(subject.claims.size).to eql(2)
end
end

context "filtering for quality_assured_approved" do
let!(:qa_approved_claim) { create(:claim, :approved, :qa_completed, :current_academic_year) }
let!(:qa_rejected_claim) { create(:claim, :rejected, :qa_completed, :current_academic_year) }

let(:filters) { {status: "quality_assured_approved"} }

it "returns all approved quality assured claims" do
expect(subject.claims).to eq([qa_approved_claim])
end
end

context "filtering for quality_assured_rejected" do
let!(:qa_approved_claim) { create(:claim, :approved, :qa_completed, :current_academic_year) }
let!(:qa_rejected_claim) { create(:claim, :rejected, :qa_completed, :current_academic_year) }

let(:filters) { {status: "quality_assured_rejected"} }

it "returns all rejected quality assured claims" do
expect(subject.claims).to eq([qa_rejected_claim])
end
end
end
end

0 comments on commit 2d0e251

Please sign in to comment.