Skip to content

Commit 668685c

Browse files
committed
Transition errored submissions to "in_review"
If all the rows have been processed but some have errors, we want to transition the submission to an "in_review" state so that the user will see the errors and is able to correct them on the frontend. Note that we're allowing transition from "pending", as well as "processed". In theory, we should only ever transition a "processing" submission to "in_review", but at the moment there is no part of the system that transitions a submission out of "pending"; instead the ingest and validation is triggered whilst they are still "pending". The plan is to update the ingest script so that it transitions the submission to "processing" when it starts, but until that is done we wan to be able to see the submissions flowing through the various states.
1 parent 07bf7ce commit 668685c

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

app/models/submission.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ class Submission < ApplicationRecord
1414
state :in_review
1515
state :completed
1616
state :rejected
17+
18+
event :ready_for_review do
19+
transitions from: %i[pending processing], to: :in_review
20+
end
1721
end
1822
end

app/models/submission_status_update.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def perform!
99
return unless submission.entries.any?
1010

1111
trigger_levy_calculation if all_entries_valid?
12+
transition_to_in_review if no_entries_pending? && some_entries_errored?
1213
end
1314

1415
private
@@ -17,6 +18,18 @@ def all_entries_valid?
1718
submission.entries.validated.count == submission.entries.count
1819
end
1920

21+
def transition_to_in_review
22+
submission.ready_for_review!
23+
end
24+
25+
def no_entries_pending?
26+
submission.entries.pending.none?
27+
end
28+
29+
def some_entries_errored?
30+
submission.entries.errored.any?
31+
end
32+
2033
def trigger_levy_calculation
2134
AWSLambdaService.new(submission_id: submission.id).trigger
2235
end

spec/models/submission_status_update_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
context 'with no "pending" entries remaining, but some having failed validation' do
6666
let(:submission) { FactoryBot.create(:submission_with_invalid_entries, aasm_state: :processing) }
6767

68+
it 'transitions the submission to "in_review"' do
69+
submission_status_check.perform!
70+
71+
expect(submission).to be_in_review
72+
end
73+
6874
it 'does not trigger a levy calculation' do
6975
expect(aws_lambda_service_double).not_to receive(:trigger)
7076

0 commit comments

Comments
 (0)