diff --git a/app/models/waste_carriers_engine/transient_registration.rb b/app/models/waste_carriers_engine/transient_registration.rb index a2c7d8bb8..f91d9c68f 100644 --- a/app/models/waste_carriers_engine/transient_registration.rb +++ b/app/models/waste_carriers_engine/transient_registration.rb @@ -36,6 +36,11 @@ class TransientRegistration scope :pending_payment, -> { submitted.where(:"financeDetails.balance".gt => 0) } scope :pending_approval, -> { submitted.where("conviction_sign_offs.0.confirmed": "no") } + scope :convictions_possible_match, -> { submitted.where("conviction_sign_offs.0.workflow_state": "possible_match") } + scope :convictions_checks_in_progress, -> { submitted.where("conviction_sign_offs.0.workflow_state": "checks_in_progress") } + scope :convictions_approved, -> { submitted.where("conviction_sign_offs.0.workflow_state": "approved") } + scope :convictions_rejected, -> { submitted.where("conviction_sign_offs.0.workflow_state": "rejected") } + # Check if the user has changed the registration type, as this incurs an additional 40GBP charge def registration_type_changed? # Don't compare registration types if the new one hasn't been set diff --git a/spec/support/shared_examples/transient_registration_scope.rb b/spec/support/shared_examples/transient_registration_scope.rb index c0765eca8..0d8546994 100644 --- a/spec/support/shared_examples/transient_registration_scope.rb +++ b/spec/support/shared_examples/transient_registration_scope.rb @@ -105,4 +105,82 @@ expect(WasteCarriersEngine::TransientRegistration.pending_approval).not_to include(in_progress_renewal) end end + + describe "conviction check scopes" do + let(:convictions_renewal) do + create( + :transient_registration, + :has_required_data, + :requires_conviction_check, + workflow_state: :renewal_received_form + ) + end + + let(:convictions_possible_match_renewal) do + convictions_renewal + end + + let(:convictions_checks_in_progress_renewal) do + convictions_renewal.conviction_sign_offs.first.begin_checks! + convictions_renewal + end + + let(:convictions_approved_renewal) do + convictions_renewal.conviction_sign_offs.first.approve!(build(:user)) + convictions_renewal + end + + let(:convictions_rejected_renewal) do + convictions_renewal.conviction_sign_offs.first.reject! + convictions_renewal + end + + describe "#convictions_possible_match" do + let(:scope) { WasteCarriersEngine::TransientRegistration.convictions_possible_match } + + it "returns renewals where a conviction_sign_off is in the possible_match state" do + expect(scope).to include(convictions_possible_match_renewal) + end + + it "does not return others" do + expect(scope).not_to include(convictions_checks_in_progress_renewal) + end + end + + describe "#convictions_checks_in_progress" do + let(:scope) { WasteCarriersEngine::TransientRegistration.convictions_checks_in_progress } + + it "returns renewals where a conviction_sign_off is in the checks_in_progress state" do + expect(scope).to include(convictions_checks_in_progress_renewal) + end + + it "does not return others" do + expect(scope).not_to include(convictions_possible_match_renewal) + end + end + + describe "#convictions_approved" do + let(:scope) { WasteCarriersEngine::TransientRegistration.convictions_approved } + + it "returns renewals where a conviction_sign_off is in the approved state" do + expect(scope).to include(convictions_approved_renewal) + end + + it "does not return others" do + expect(scope).not_to include(convictions_possible_match_renewal) + end + end + + describe "#convictions_rejected" do + let(:scope) { WasteCarriersEngine::TransientRegistration.convictions_rejected } + + it "returns renewals where a conviction_sign_off is in the rejected state" do + expect(scope).to include(convictions_rejected_renewal) + end + + it "does not return others" do + expect(scope).not_to include(convictions_possible_match_renewal) + end + end + end end