2017-05-12 17:41:03 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-10-03 16:19:25 +02:00
|
|
|
RSpec.describe WeeklyOverviewJob, type: :job do
|
2017-05-12 17:41:03 +02:00
|
|
|
describe 'perform' do
|
|
|
|
let!(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
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
|
|
|
|
Flipflop::FeatureSet.current.test!.switch!(:weekly_overview, true)
|
|
|
|
end
|
2017-05-19 16:21:11 +02:00
|
|
|
|
|
|
|
context 'with one gestionnaire with one overview' do
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2017-05-19 16:21:11 +02:00
|
|
|
expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(overview)
|
|
|
|
allow(GestionnaireMailer).to receive(:last_week_overview).and_return(mailer_double)
|
2017-10-03 16:19:25 +02:00
|
|
|
WeeklyOverviewJob.new.perform
|
2017-05-19 16:21:11 +02:00
|
|
|
end
|
|
|
|
|
2018-02-21 17:40:41 +01:00
|
|
|
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire) }
|
|
|
|
it { expect(mailer_double).to have_received(:deliver_later) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
context 'with one gestionnaire with no overviews' do
|
2018-04-18 12:24:37 +02:00
|
|
|
before do
|
2017-05-19 16:21:11 +02:00
|
|
|
expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(nil)
|
|
|
|
allow(GestionnaireMailer).to receive(:last_week_overview)
|
2017-10-03 16:19:25 +02:00
|
|
|
WeeklyOverviewJob.new.perform
|
2017-05-19 16:21:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) }
|
|
|
|
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
|
|
|
|
Flipflop::FeatureSet.current.test!.switch!(:weekly_overview, false)
|
2017-05-19 16:21:11 +02:00
|
|
|
allow(Gestionnaire).to receive(:all)
|
2017-10-03 16:19:25 +02:00
|
|
|
WeeklyOverviewJob.new.perform
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
|
2017-05-19 16:21:11 +02:00
|
|
|
it { expect(Gestionnaire).not_to receive(:all) }
|
2017-05-12 17:41:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|