diff --git a/app/forms/admin/claims_filter_form.rb b/app/forms/admin/claims_filter_form.rb index 9e37bb314e..5148a9380d 100644 --- a/app/forms/admin/claims_filter_form.rb +++ b/app/forms/admin/claims_filter_form.rb @@ -67,8 +67,12 @@ def claims @claims = @claims.unassigned if unassigned? @claims = @claims.includes(:tasks, eligibility: [:claim_school, :current_school]) - @claims = @claims.order(:submitted_at) + @claims = @claims.select("DISTINCT ON (claims.id, claims.submitted_at) claims.id") + + @claims = Claim.where(id: @claims) + + @claims = @claims.order(:submitted_at) @claims end diff --git a/spec/forms/admin/claims_filter_form_spec.rb b/spec/forms/admin/claims_filter_form_spec.rb new file mode 100644 index 0000000000..7636442208 --- /dev/null +++ b/spec/forms/admin/claims_filter_form_spec.rb @@ -0,0 +1,64 @@ +require "rails_helper" + +RSpec.describe Admin::ClaimsFilterForm, type: :model do + describe "#claims" do + context "when the status is awaiting_provider_verification" do + it "returns the expected claims" do + claim_awaiting_provider_verification_1 = build( + :claim, + :submitted + ) + + create( + :further_education_payments_eligibility, + claim: claim_awaiting_provider_verification_1, + flagged_as_duplicate: false + ) + + claim_awaiting_provider_verification_2 = build( + :claim, + :submitted + ) + + create( + :further_education_payments_eligibility, + claim: claim_awaiting_provider_verification_2, + flagged_as_duplicate: true + ) + + create( + :note, + claim: claim_awaiting_provider_verification_2, + label: "provider_verification" + ) + + create( + :note, + claim: claim_awaiting_provider_verification_2, + label: "provider_verification" + ) + + _claim_not_awating_provider_verification = build(:claim, :submitted) + + create( + :further_education_payments_eligibility, + :verified + ) + + form = described_class.new( + session: {}, + filters: { + status: "awaiting_provider_verification" + } + ) + + expect(form.claims).to match_array( + [ + claim_awaiting_provider_verification_1, + claim_awaiting_provider_verification_2 + ] + ) + end + end + end +end