Skip to content

Commit

Permalink
Add scope to deal with conviction_sign_offs from frontend (#574)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/RUBY-791

Any conviction_sign_offs that are created in the waste-carriers-frontend don't get a workflow_state when they are created. So we need an extra scope to deal with them. This will allow us to list them on the dashboard in the back office.
  • Loading branch information
irisfaraway committed Dec 3, 2019
1 parent 227691e commit 87dfdcf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ module CanFilterConvictionStatus
scope :convictions_rejected, lambda {
where("conviction_sign_offs.0.workflow_state": "rejected")
}
# This is to catch historical conviction_sign_offs which were only created and modified by waste-carriers-frontend
# and have no workflow_state as a result. We want ones which have not been confirmed and are in a pending state.
scope :convictions_new_without_status, lambda {
where(:"conviction_sign_offs.0".exists => true,
:"conviction_sign_offs.0.workflow_state".exists => false,
:"conviction_sign_offs.0.confirmed".ne => "yes",
"metaData.status": "PENDING")
}
end
end
end
52 changes: 52 additions & 0 deletions spec/support/shared_examples/can_filter_conviction_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,44 @@
record
end

let(:no_status_pending) do
record = described_class.new(
conviction_sign_offs: [
WasteCarriersEngine::ConvictionSignOff.new
],
metaData: { status: "PENDING" }
)
# Skip the validation so we don't have to include addresses, etc
record.save(validate: false)
record.conviction_sign_offs.first.unset(:workflow_state)
record
end

let(:no_status_active) do
record = described_class.new(
conviction_sign_offs: [
WasteCarriersEngine::ConvictionSignOff.new
],
metaData: { status: "ACTIVE" }
)
# Skip the validation so we don't have to include addresses, etc
record.save(validate: false)
record.conviction_sign_offs.first.unset(:workflow_state)
record
end

let(:no_status_approved) do
record = described_class.new(
conviction_sign_offs: [
WasteCarriersEngine::ConvictionSignOff.new(confirmed: "yes")
]
)
# Skip the validation so we don't have to include addresses, etc
record.save(validate: false)
record.conviction_sign_offs.first.unset(:workflow_state)
record
end

describe "convictions_possible_match" do
let(:scope) { described_class.convictions_possible_match }

Expand Down Expand Up @@ -88,4 +126,18 @@
expect(scope).to include(rejected)
end
end

describe "convictions_new_without_status" do
let(:scope) { described_class.convictions_new_without_status }

it "only returns results with the correct status" do
expect(scope).to_not include(possible_match)
expect(scope).to_not include(checks_in_progress)
expect(scope).to_not include(approved)
expect(scope).to_not include(rejected)
expect(scope).to include(no_status_pending)
expect(scope).to_not include(no_status_active)
expect(scope).to_not include(no_status_approved)
end
end
end

0 comments on commit 87dfdcf

Please sign in to comment.