From aaa470a292d8b2d4d7e8421a3f7eb002fccfd804 Mon Sep 17 00:00:00 2001 From: Alkesh Vaghmaria Date: Mon, 23 Sep 2024 14:18:26 +0100 Subject: [PATCH] check for provider email being sent instead of matching_details task --- app/models/claim.rb | 16 ++++----------- spec/models/claim_spec.rb | 43 ++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/app/models/claim.rb b/app/models/claim.rb index c2bf0cb992..b011748a23 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -212,17 +212,12 @@ class Claim < ApplicationRecord scope :awaiting_qa, -> { approved.qa_required.where(qa_completed_at: nil) } scope :qa_required, -> { where(qa_required: true) } scope :awaiting_further_education_provider_verification, -> do - # TODO change this to check provider email has been sent joins("INNER JOIN further_education_payments_eligibilities ON further_education_payments_eligibilities.id = claims.eligibility_id") - # .left_outer_joins(:notes) - # .where(notes: {label: [nil, "provider_verification"]}) - .left_outer_joins(:tasks) + .left_outer_joins(:notes) .where("further_education_payments_eligibilities.verification = '{}'") - .where(tasks: {name: [nil, "matching_details"]}) .and( Claim.where("further_education_payments_eligibilities.flagged_as_duplicate = FALSE") - .or(Claim.where("further_education_payments_eligibilities.flagged_as_duplicate = TRUE").and(Claim.where(tasks: {name: "matching_details", passed: true}))) - # .or(Claim.where("further_education_payments_eligibilities.flagged_as_duplicate = TRUE").and(Claim.where(notes: {label: "provider_verification"}))) + .or(Claim.where("further_education_payments_eligibilities.flagged_as_duplicate = TRUE").and(Claim.where(notes: {label: "provider_verification"}))) ) end @@ -454,11 +449,8 @@ def awaiting_provider_verification? return false if eligibility.verified? - if tasks.where(name: "matching_details").any? - tasks.where(name: "matching_details", passed: true).any? - else - Claim::MatchingAttributeFinder.new(self).matching_claims.empty? - end + # TODO - duplication with app/models/policies/further_education_payments/admin_provider_verification_task_presenter.rb + !eligibility.flagged_as_duplicate? || notes.where(label: "provider_verification").any? end private diff --git a/spec/models/claim_spec.rb b/spec/models/claim_spec.rb index dfb7e3e2e4..3b3f60ec7b 100644 --- a/spec/models/claim_spec.rb +++ b/spec/models/claim_spec.rb @@ -909,21 +909,20 @@ describe ".awaiting_further_education_provider_verification" do subject { described_class.awaiting_further_education_provider_verification } - let!(:claim_not_verified_without_matching_details_task) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible) } - let!(:claim_not_verified_with_matching_details_task_answered_no) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } - let!(:claim_not_verified_with_matching_details_task_answered_yes) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } - let!(:claim_not_verified_with_duplicate_claims) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } + let!(:claim_not_verified_provider_email_automatically_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible) } + let!(:claim_not_verified_provider_email_not_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } + let!(:claim_not_verified_has_duplicates_provider_email_not_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } + let!(:claim_not_verified_has_duplicates_provider_email_manually_sent) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } let!(:claim_with_fe_provider_verification) { create(:claim, policy: Policies::FurtherEducationPayments, eligibility_trait: :verified) } let!(:non_fe_claim) { create(:claim, policy: Policies::StudentLoans) } before do - create(:task, claim: claim_not_verified_with_matching_details_task_answered_yes, name: "matching_details", passed: true) - create(:task, claim: claim_not_verified_with_matching_details_task_answered_no, name: "matching_details", passed: false) - create(:task, claim: claim_not_verified_with_matching_details_task_answered_no, name: "student_loan_plan", passed: true) + create(:note, claim: claim_not_verified_has_duplicates_provider_email_manually_sent, label: "provider_verification") + create(:note, claim: claim_not_verified_provider_email_not_sent, label: "student_loan_plan") end it "returns claims that have not been verified by the provider, and have no matching_details task or have a passed matching_details task" do - is_expected.to match_array([claim_not_verified_without_matching_details_task, claim_not_verified_with_matching_details_task_answered_yes]) + is_expected.to match_array([claim_not_verified_provider_email_automatically_sent, claim_not_verified_has_duplicates_provider_email_manually_sent]) end end @@ -1343,31 +1342,25 @@ subject { claim.awaiting_provider_verification? } context "when the eligiblity is not verified" do - let(:claim) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible) } + context "when there are no duplicates" do + let(:claim) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible) } - context "there is not a matching_details task" do - context "when there are matching claims" do - before { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible, email_address: claim.email_address) } + it { is_expected.to be true } + end + + context "when there are duplicates" do + let(:claim) { create(:claim, :submitted, policy: Policies::FurtherEducationPayments, eligibility_trait: :eligible_duplicate) } + context "the provider email has not been sent" do it { is_expected.to be false } end - context "when there are no matching claims" do + context "when the provider email has been sent" do + before { create(:note, claim: claim, label: "provider_verification") } + it { is_expected.to be true } end end - - context "when there is a passed matching_details task" do - before { create(:task, claim: claim, name: "matching_details", passed: true) } - - it { is_expected.to be true } - end - - context "when there is a failed matching_details task" do - before { create(:task, claim: claim, name: "matching_details", passed: false) } - - it { is_expected.to be false } - end end context "when the eligiblity is verified" do