|
| 1 | +require 'rails_helper' |
| 2 | + |
| 3 | +RSpec.describe SubmissionCompletion do |
| 4 | + describe '#perform' do |
| 5 | + let(:complete_submission) { SubmissionCompletion.new(submission) } |
| 6 | + let(:task) { FactoryBot.create(:task, status: :in_progress) } |
| 7 | + |
| 8 | + context 'given an "in review" submission' do |
| 9 | + context 'with validated entries' do |
| 10 | + let(:submission) { FactoryBot.create(:submission_with_validated_entries, aasm_state: 'in_review', task: task) } |
| 11 | + |
| 12 | + it 'transitions the submission to completed' do |
| 13 | + complete_submission.perform! |
| 14 | + |
| 15 | + expect(submission).to be_completed |
| 16 | + end |
| 17 | + |
| 18 | + it 'transitions the task to completed' do |
| 19 | + complete_submission.perform! |
| 20 | + |
| 21 | + expect(task).to be_completed |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + context 'with some invalid entries' do |
| 26 | + let(:submission) { FactoryBot.create(:submission_with_invalid_entries, task: task) } |
| 27 | + |
| 28 | + it 'leaves the submission in the "in_review" state' do |
| 29 | + expect { complete_submission.perform! }.not_to change { submission.aasm_state } |
| 30 | + end |
| 31 | + |
| 32 | + it 'leaves the task in the "in_progress" state' do |
| 33 | + expect { complete_submission.perform! }.not_to change { task.status } |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context 'given a "processing" submission' do |
| 39 | + let(:submission) { FactoryBot.create(:submission_with_unprocessed_entries, aasm_state: :processing, task: task) } |
| 40 | + |
| 41 | + it 'leaves the submission in its current state' do |
| 42 | + expect { complete_submission.perform! }.not_to change { submission.aasm_state } |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | +end |
0 commit comments