WeeklyOverviewWorker: add worker to send the week overview
This commit is contained in:
parent
8dabdcc6c4
commit
c4c2dc78a2
2 changed files with 40 additions and 0 deletions
10
app/workers/weekly_overview_worker.rb
Normal file
10
app/workers/weekly_overview_worker.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class WeeklyOverviewWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(*args)
|
||||
Gestionnaire.all
|
||||
.map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] }
|
||||
.reject { |_, overview| overview.nil? }
|
||||
.each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now }
|
||||
end
|
||||
end
|
30
spec/workers/weekly_overview_worker_spec.rb
Normal file
30
spec/workers/weekly_overview_worker_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe WeeklyOverviewWorker, type: :worker do
|
||||
describe 'perform' do
|
||||
let!(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:overview) { double('overview') }
|
||||
let(:mailer_double) { double('mailer', deliver_now: true) }
|
||||
|
||||
context 'with one gestionnaire with one overview' do
|
||||
before :each 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)
|
||||
WeeklyOverviewWorker.new.perform
|
||||
end
|
||||
|
||||
it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) }
|
||||
it { expect(mailer_double).to have_received(:deliver_now) }
|
||||
end
|
||||
|
||||
context 'with one gestionnaire with no overviews' do
|
||||
before :each do
|
||||
expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(nil)
|
||||
allow(GestionnaireMailer).to receive(:last_week_overview)
|
||||
WeeklyOverviewWorker.new.perform
|
||||
end
|
||||
|
||||
it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue