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') }
|
2018-02-21 17:40:41 +01:00
|
|
|
let(:mailer_double) { double('mailer', deliver_later: true) }
|
2017-05-12 17:41:03 +02:00
|
|
|
|
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
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
context 'with one instructeur with one overview' do
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
expect_any_instance_of(Instructeur).to receive(:last_week_overview).and_return(overview)
|
|
|
|
allow(InstructeurMailer).to receive(:last_week_overview).and_return(mailer_double)
|
2020-11-13 14:34:53 +01:00
|
|
|
Cron::WeeklyOverviewJob.new.perform
|
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
|
2019-08-06 11:02:54 +02:00
|
|
|
expect_any_instance_of(Instructeur).to receive(:last_week_overview).and_return(nil)
|
|
|
|
allow(InstructeurMailer).to receive(:last_week_overview)
|
2020-11-13 14:34:53 +01:00
|
|
|
Cron::WeeklyOverviewJob.new.perform
|
2017-05-19 16:21:11 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(InstructeurMailer).not_to have_received(:last_week_overview) }
|
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
|
2019-08-06 11:02:54 +02:00
|
|
|
allow(Instructeur).to receive(:all)
|
2020-11-13 14:34:53 +01:00
|
|
|
Cron::WeeklyOverviewJob.new.perform
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it { expect(Instructeur).not_to receive(:all) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|