Skip to content

Commit

Permalink
Merge pull request #9368 from DFE-Digital/pass-cycle-week-to-report-s…
Browse files Browse the repository at this point in the history
…cheduler

RecruitmentReportScheduler accepts explicit cycle_week argument
  • Loading branch information
inulty-dfe authored May 16, 2024
2 parents 9fc9308 + 97948e5 commit 183fc85
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
module Publications
class RecruitmentPerformanceReportScheduler
def initialize(cycle_week: CycleTimetable.current_cycle_week.pred)
@cycle_week = cycle_week
end

def call
schedule_national_report
schedule_provider_report
end

private

attr_accessor :cycle_week

def schedule_national_report
return if Publications::NationalRecruitmentPerformanceReport.exists?(cycle_week:)

Expand All @@ -25,9 +31,5 @@ def schedule_provider_report
)
end
end

def cycle_week
CycleTimetable.current_cycle_week.pred
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
let(:provider_worker) { Publications::ProviderRecruitmentPerformanceReportWorker }
let(:national_worker) { Publications::NationalRecruitmentPerformanceReportWorker }
let(:provider) { create(:provider) }
let(:previous_cycle_week) { CycleTimetable.current_cycle_week.pred }
let(:cycle_week) { CycleTimetable.current_cycle_week.pred }

context 'provider report is generated for appropriate providers' do
before do
allow(provider_worker).to receive(:perform_async)
provider
allow(ProvidersForRecruitmentPerformanceReportQuery).to receive(:call).with(cycle_week: previous_cycle_week).and_return(Provider)
allow(ProvidersForRecruitmentPerformanceReportQuery).to receive(:call).with(cycle_week:).and_return(Provider)
end

it 'creates a report for a provider who received an application last week' do
described_class.new.call

expect(provider_worker).to have_received(:perform_async).with(provider.id, previous_cycle_week)
expect(provider_worker).to have_received(:perform_async).with(provider.id, cycle_week)
end

context 'explicit cycle_week is passed' do
let(:cycle_week) { 2 }

it 'creates a report for a provider who received an application before cycle_week' do
described_class.new(cycle_week:).call

expect(provider_worker).to have_received(:perform_async).with(provider.id, cycle_week)
end
end
end

Expand All @@ -28,19 +38,29 @@
it 'creates a National report' do
described_class.new.call

expect(national_worker).to have_received(:perform_async).with(previous_cycle_week)
expect(national_worker).to have_received(:perform_async).with(cycle_week)
end

it 'does not create a National report worker when a report already exists' do
Publications::NationalRecruitmentPerformanceReport.create!(
statistics: {},
publication_date: Time.zone.today,
cycle_week: previous_cycle_week,
cycle_week:,
)

described_class.new.call

expect(national_worker).not_to have_received(:perform_async).with(previous_cycle_week)
expect(national_worker).not_to have_received(:perform_async).with(cycle_week)
end

context 'explicit cycle_week is passed' do
let(:cycle_week) { 2 }

it 'creates a national report for the cycle_week value' do
described_class.new(cycle_week:).call

expect(national_worker).to have_received(:perform_async).with(cycle_week)
end
end
end
end

0 comments on commit 183fc85

Please sign in to comment.