docbrown/spec/workers/notifications/welcome_notification_worker_spec.rb
Vaidehi Joshi 3bc0f49861
Only send notifications that belong to an active broadcast (#6319) [deploy]
* Use active in place of sent on internal broadcast routes

* Add and use active scope on broadcasts

* Update seeds + specs to use active broadcasts

* Add note about active broadcasts to /internal/broadcasts page
2020-02-27 08:02:45 -08:00

39 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe Notifications::WelcomeNotificationWorker, type: :worker do
describe "#perform" do
let(:broadcast) { create(:broadcast, :onboarding, :active) }
let(:inactive_broadcast) { create(:broadcast, :onboarding) }
let(:user) { create(:user) }
let(:service) { Notifications::WelcomeNotification::Send }
let(:worker) { subject }
before do
allow(service).to receive(:call)
end
context "with an active broadcast" do
it "calls a service" do
worker.perform(user.id, broadcast.id)
expect(service).to have_received(:call).with(user.id, broadcast).once
end
end
context "with an inactive broadcast" do
it "does not call a service" do
worker.perform(user.id, inactive_broadcast.id)
expect(service).not_to have_received(:call)
end
end
context "when there is a non-existent broadcast" do
before do
broadcast.destroy
end
it "does nothing" do
worker.perform(user.id, broadcast.id)
expect(service).not_to have_received(:call)
end
end
end
end