|
| 1 | +require 'rails_helper' |
| 2 | + |
| 3 | +RSpec.describe SubmissionStatusUpdate do |
| 4 | + describe '#perform' do |
| 5 | + let(:aws_lambda_service_double) { double(trigger: true) } |
| 6 | + let(:submission_status_check) { SubmissionStatusUpdate.new(submission) } |
| 7 | + |
| 8 | + before do |
| 9 | + allow(AWSLambdaService).to receive(:new).and_return(aws_lambda_service_double) |
| 10 | + end |
| 11 | + |
| 12 | + context 'given a "processing" submission' do |
| 13 | + context 'with "pending" entries' do |
| 14 | + let(:submission) { FactoryBot.create(:submission_with_pending_entries, aasm_state: :processing) } |
| 15 | + |
| 16 | + it 'leaves the submission in a "processing" state' do |
| 17 | + submission_status_check.perform! |
| 18 | + |
| 19 | + expect(submission).to be_processing |
| 20 | + end |
| 21 | + |
| 22 | + it 'does not trigger a levy calculation' do |
| 23 | + expect(aws_lambda_service_double).not_to receive(:trigger) |
| 24 | + |
| 25 | + submission_status_check.perform! |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + context 'with all entries validated' do |
| 30 | + let(:submission) { FactoryBot.create(:submission_with_validated_entries, aasm_state: :processing) } |
| 31 | + |
| 32 | + it 'leaves the submission in a "processing" state' do |
| 33 | + submission_status_check.perform! |
| 34 | + |
| 35 | + expect(submission).to be_processing |
| 36 | + end |
| 37 | + |
| 38 | + it 'triggers a levy calculation' do |
| 39 | + expect(aws_lambda_service_double).to receive(:trigger) |
| 40 | + |
| 41 | + submission_status_check.perform! |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context 'with some "pending" entries and some "errored" entries' do |
| 46 | + let(:submission) do |
| 47 | + FactoryBot.create(:submission_with_pending_entries, aasm_state: :processing).tap do |submission| |
| 48 | + create(:errored_submission_entry, submission: submission) |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + it 'leaves the submission in a "processing"' do |
| 53 | + submission_status_check.perform! |
| 54 | + |
| 55 | + expect(submission).to be_processing |
| 56 | + end |
| 57 | + |
| 58 | + it 'does not trigger a levy calculation' do |
| 59 | + expect(aws_lambda_service_double).not_to receive(:trigger) |
| 60 | + |
| 61 | + submission_status_check.perform! |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'with no "pending" entries remaining, but some having failed validation' do |
| 66 | + let(:submission) { FactoryBot.create(:submission_with_invalid_entries, aasm_state: :processing) } |
| 67 | + |
| 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 | + |
| 74 | + it 'does not trigger a levy calculation' do |
| 75 | + expect(aws_lambda_service_double).not_to receive(:trigger) |
| 76 | + |
| 77 | + submission_status_check.perform! |
| 78 | + end |
| 79 | + end |
| 80 | + end |
| 81 | + end |
| 82 | +end |
0 commit comments