* Add Welcome Thread Broadcast to generator.rb * Add welcome trait to broadcasts.rb * Add additional tests around welcome_broadcasts: - ensure that the correct Broadcast is sent - ensure that a User only receives a single Notification - ensure that only certain Users receieve the Notification * Refactor and remove unncessary code from generator.rb and generator_spec.rb * Refactor generator_spec and eagerly load welcome_thread_comment to get spec passing * Initialize user in place of receiver_id in generator.rb * Add before action to make generator_spec more readable * Add latest_published_thread method to generator.rb * Update generator.rb to be reusable with latest_published_thread * Update generator_spec to use welcome tags for Article obj * Create mascot_account using let to reduce User creation in spec * Adjust expectation for a User who should not receive a notification
39 lines
1.1 KiB
Ruby
39 lines
1.1 KiB
Ruby
require "rails_helper"
|
|
RSpec.describe Notifications::WelcomeNotificationWorker, type: :worker do
|
|
describe "#perform" do
|
|
let(:broadcast) { create(:onboarding_broadcast, :active) }
|
|
let(:inactive_broadcast) { create(:onboarding_broadcast) }
|
|
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
|