Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scopes for different conviction check states #304

Merged
merged 5 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/waste_carriers_engine/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions spec/support/shared_examples/transient_registration_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,82 @@
expect(WasteCarriersEngine::TransientRegistration.pending_approval).not_to include(in_progress_renewal)
end
end

describe "conviction check scopes" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be warned, this is essentially getting you to clean up my mess!

The way the tests are setup for the conviction check scopes differs from the way that's done in the rest of this file. I think within the same file we should aim to try and keep the pattern consistent. I'm happy to go with what you have done (what I did was based on my limited knowledge and abilities), but would you be ok as a bit of a 'boy scout exercise' to refactor the setup for the previous tests to match?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense! I'll have a bash now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I wonder if it would make more sense to do it as a separate PR, just to keep the commit history a bit clearer? Just started it and I don't think it'll take long but it will clutter up the diff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. That talk really sparked something! 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to practice what I preach in the retros 👼

New PR here: #305 I'll let you know once it's ready!

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