demarches-normaliennes/spec/jobs/weekly_overview_job_spec.rb

47 lines
1.6 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2017-10-03 16:19:25 +02:00
RSpec.describe WeeklyOverviewJob, type: :job do
describe 'perform' do
let!(:gestionnaire) { create(:gestionnaire) }
let(:overview) { double('overview') }
let(:mailer_double) { double('mailer', deliver_later: true) }
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
context 'with one gestionnaire with one overview' do
2018-04-18 12:24:37 +02:00
before do
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
end
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire) }
it { expect(mailer_double).to have_received(:deliver_later) }
end
context 'with one gestionnaire with no overviews' do
2018-04-18 12:24:37 +02:00
before do
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
end
it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) }
end
end
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)
allow(Gestionnaire).to receive(:all)
2017-10-03 16:19:25 +02:00
WeeklyOverviewJob.new.perform
end
it { expect(Gestionnaire).not_to receive(:all) }
end
end
end