2020-11-13 14:34:53 +01:00
|
|
|
RSpec.describe Cron::WeeklyOverviewJob, type: :job do
|
2017-05-12 17:41:03 +02:00
|
|
|
describe 'perform' do
|
2019-08-06 11:02:54 +02:00
|
|
|
let!(:instructeur) { create(:instructeur) }
|
2017-05-12 17:41:03 +02:00
|
|
|
let(:overview) { double('overview') }
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
context 'if the feature is enabled' do
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2019-07-31 12:26:07 +02:00
|
|
|
Rails.application.config.ds_weekly_overview = true
|
|
|
|
end
|
|
|
|
after do
|
|
|
|
Rails.application.config.ds_weekly_overview = false
|
2018-04-18 12:24:37 +02:00
|
|
|
end
|
2017-05-19 16:21:11 +02:00
|
|
|
|
2023-03-02 19:01:14 +01:00
|
|
|
subject(:run_job) { Cron::WeeklyOverviewJob.new.perform }
|
|
|
|
# See also spec/mailers/instructeur_mailer_spec.rb
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'with one instructeur with one overview' do
|
2023-03-02 19:01:14 +01:00
|
|
|
let(:mailer_double) { double('mailer', deliver_later: true) }
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
allow(InstructeurMailer).to receive(:last_week_overview).and_return(mailer_double)
|
2023-03-02 19:01:14 +01:00
|
|
|
run_job
|
2017-05-19 16:21:11 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(InstructeurMailer).to have_received(:last_week_overview).with(instructeur) }
|
2018-02-21 17:40:41 +01:00
|
|
|
it { expect(mailer_double).to have_received(:deliver_later) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'with one instructeur with no overviews' do
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2023-03-02 19:01:14 +01:00
|
|
|
allow(InstructeurMailer).to receive(:last_week_overview).and_return(nil)
|
|
|
|
run_job
|
2017-05-19 16:21:11 +02:00
|
|
|
end
|
|
|
|
|
2023-03-02 19:01:14 +01:00
|
|
|
it { expect(InstructeurMailer).to have_received(:last_week_overview).with(instructeur) }
|
2023-11-09 17:27:55 +01:00
|
|
|
it { expect { run_job }.not_to raise_error }
|
2017-05-19 16:21:11 +02:00
|
|
|
end
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
context 'if the feature is disabled' do
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2023-03-02 19:01:14 +01:00
|
|
|
allow(Instructeur).to receive(:find_each)
|
2020-11-13 14:34:53 +01:00
|
|
|
Cron::WeeklyOverviewJob.new.perform
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2023-03-02 19:01:14 +01:00
|
|
|
it { expect(Instructeur).not_to receive(:find_each) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|