Skip to content

Commit

Permalink
Merge pull request #9521 from DFE-Digital/779-prevent-the-cancelunsub…
Browse files Browse the repository at this point in the history
…mittedapplicationsworker-from-running-for-2024-candidates

Reinstate cancel unsubmitted applications worker with specific deadline
  • Loading branch information
elceebee authored Jul 1, 2024
2 parents be54421 + 8c1a8d3 commit 69bc726
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 40 deletions.
4 changes: 4 additions & 0 deletions app/helpers/cycle_timetable_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def after_apply_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_deadline(year) + 1.day
end

def cancel_application_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_deadline(year)
end

def before_apply_deadline(year = CycleTimetable.current_year)
CycleTimetable.apply_deadline(year) - 1.day
end
Expand Down
4 changes: 4 additions & 0 deletions app/services/cycle_timetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def self.reject_by_default(year = current_year)
date(:reject_by_default, year)
end

def self.cancel_unsubmitted_applications?
current_date.to_date == apply_deadline.to_date
end

def self.find_closes(year = current_year)
date(:find_closes, year)
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/cancel_unsubmitted_applications_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def perform
private

def unsubmitted_applications_from_earlier_cycle
return [] unless CycleTimetable.between_cycles?
return [] unless CycleTimetable.cancel_unsubmitted_applications?

ApplicationForm
.where(submitted_at: nil)
Expand Down
2 changes: 1 addition & 1 deletion config/clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Clock
every(1.day, 'SendApplyToMultipleCoursesWhenInactiveEmailToCandidatesWorker', at: '10:00') { SendApplyToMultipleCoursesWhenInactiveEmailToCandidatesWorker.perform_async }
every(1.day, 'DfE::Analytics::EntityTableCheckJob', at: '00:30') { DfE::Analytics::EntityTableCheckJob.perform_later }

# every(1.day, 'CancelUnsubmittedApplicationsWorker', at: '11:00') { CancelUnsubmittedApplicationsWorker.perform_async }
every(1.day, 'CancelUnsubmittedApplicationsWorker', at: '19:00') { CancelUnsubmittedApplicationsWorker.perform_async }

# Daily jobs - mon-thurs only
every(1.day, 'SendStatsSummaryToSlack', at: '17:00', if: ->(period) { period.wday.between?(1, 4) }) { SendStatsSummaryToSlack.new.perform }
Expand Down
36 changes: 36 additions & 0 deletions spec/services/cycle_timetable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,4 +642,40 @@ def create_application_for(recruitment_cycle_year)
end
end
end

describe '#cancel_unsubmitted_applicaions?' do
before { TestSuiteTimeMachine.travel_permanently_to(date) }

context 'mid-cycle' do
let(:date) { mid_cycle }

it 'returns false' do
expect(described_class.cancel_unsubmitted_applications?).to be false
end
end

context 'on reject by default date' do
let(:date) { described_class.reject_by_default }

it 'returns false' do
expect(described_class.cancel_unsubmitted_applications?).to be false
end
end

context 'on cancel date' do
let(:date) { cancel_application_deadline }

it 'returns false' do
expect(described_class.cancel_unsubmitted_applications?).to be true
end
end

context 'after find reopens' do
let(:date) { after_apply_reopens }

it 'returns false' do
expect(described_class.cancel_unsubmitted_applications?).to be false
end
end
end
end
108 changes: 70 additions & 38 deletions spec/workers/cancel_unsubmitted_applications_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe CancelUnsubmittedApplicationsWorker do
describe '#perform', time: after_apply_deadline do
describe '#perform' do
let(:unsubmitted_application_from_this_year) do
create(:application_form,
submitted_at: nil,
Expand All @@ -28,48 +28,80 @@
recruitment_cycle_year: RecruitmentCycle.current_year))
end

it 'cancels any unsubmitted applications from the last cycle' do
unsubmitted_application_from_this_year
unsubmitted_application_from_last_year
let(:hidden_application_from_this_year) do
create(:application_form,
submitted_at: nil,
candidate: create(:candidate, hide_in_reporting: true),
recruitment_cycle_year: RecruitmentCycle.current_year,
application_choices: [create_an_application_choice(:unsubmitted, current_year_course_option)])
end

hidden_application_from_this_year = create(
:application_form,
submitted_at: nil,
candidate: create(:candidate, hide_in_reporting: true),
recruitment_cycle_year: RecruitmentCycle.current_year,
application_choices: [create_an_application_choice(:unsubmitted, current_year_course_option)],
)

rejected_application_from_this_year = create(
:application_form,
recruitment_cycle_year: RecruitmentCycle.current_year,
application_choices: [create_an_application_choice(:rejected, current_year_course_option)],
)

unsubmitted_cancelled_application_from_this_year = create(
:application_form,
submitted_at: nil,
recruitment_cycle_year: RecruitmentCycle.current_year,
application_choices: [create_an_application_choice(:application_not_sent, current_year_course_option)],
)

described_class.new.perform

expect(unsubmitted_application_from_this_year.reload.application_choices.first).to be_application_not_sent
expect(unsubmitted_application_from_last_year.reload.application_choices.first).not_to be_application_not_sent
expect(rejected_application_from_this_year.reload.application_choices.first).not_to be_application_not_sent
expect(hidden_application_from_this_year.reload.application_choices.first).not_to be_application_not_sent
expect(unsubmitted_cancelled_application_from_this_year.reload.application_choices.first).to be_application_not_sent
let(:rejected_application_from_this_year) do
create(:application_form,
recruitment_cycle_year: RecruitmentCycle.current_year,
application_choices: [create_an_application_choice(:rejected, current_year_course_option)])
end

let(:unsubmitted_cancelled_application_from_this_year) do
create(:application_form,
submitted_at: nil,
recruitment_cycle_year: RecruitmentCycle.current_year,
application_choices: [create_an_application_choice(:application_not_sent, current_year_course_option)])
end

it 'does not run once in the new cycle' do
travel_temporarily_to(CycleTimetable.apply_opens) do
unsubmitted_application_from_this_year
unsubmitted_application_from_last_year
let(:create_test_applications) do
unsubmitted_cancelled_application_from_this_year
rejected_application_from_this_year
hidden_application_from_this_year
unsubmitted_application_from_last_year
unsubmitted_application_from_this_year
end

context 'for previous cycle, current cycle, next cycle' do
[RecruitmentCycle.previous_year, RecruitmentCycle.current_year, RecruitmentCycle.next_year].each do |year|
context 'on cancel application deadline', time: cancel_application_deadline(year) do
it 'cancels applications' do
create_test_applications

described_class.new.perform

expect(unsubmitted_application_from_this_year.reload.application_choices.first).to be_application_not_sent
expect(unsubmitted_application_from_last_year.reload.application_choices.first).not_to be_application_not_sent
expect(rejected_application_from_this_year.reload.application_choices.first).not_to be_application_not_sent
expect(hidden_application_from_this_year.reload.application_choices.first).not_to be_application_not_sent
expect(unsubmitted_cancelled_application_from_this_year.reload.application_choices.first).to be_application_not_sent
end
end

context 'between cycles, but not on cancel date', time: after_apply_deadline(year) do
it 'does not cancel any applications' do
create_test_applications

task = described_class.new.perform

expect(task).to eq []
end
end

context 'in mid-cycle', time: mid_cycle(year) do
it 'does not run once in the middle of a cycle' do
create_test_applications

task = described_class.new.perform

expect(task).to eq []
end
end

context 'after_apply_reopens', time: after_apply_reopens(year) do
it 'does not run once the new cycle starts' do
create_test_applications

task = described_class.new.perform
task = described_class.new.perform

expect(task).to eq []
expect(task).to eq []
end
end
end
end
end
Expand Down

0 comments on commit 69bc726

Please sign in to comment.