Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecruitmentReportScheduler accepts explicit cycle_week argument #9368

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, what is pred?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predecessor. It's the number before. Opposite of succ

@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
Loading