publish_announcement_reaction_worker_spec.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe PublishAnnouncementReactionWorker do
  4. let(:worker) { described_class.new }
  5. describe '#perform' do
  6. before { Fabricate(:account, user: Fabricate(:user, current_sign_in_at: 1.hour.ago)) }
  7. let(:announcement) { Fabricate(:announcement) }
  8. let(:name) { 'name value' }
  9. it 'sends the announcement and name to the service when subscribed' do
  10. allow(redis).to receive(:exists?).and_return(true)
  11. allow(redis).to receive(:publish)
  12. worker.perform(announcement.id, name)
  13. expect(redis).to have_received(:publish)
  14. end
  15. it 'does not send the announcement and name to the service when not subscribed' do
  16. allow(redis).to receive(:exists?).and_return(false)
  17. allow(redis).to receive(:publish)
  18. worker.perform(announcement.id, name)
  19. expect(redis).to_not have_received(:publish)
  20. end
  21. it 'returns true for non-existent record' do
  22. result = worker.perform(123_123_123, name)
  23. expect(result).to be(true)
  24. end
  25. end
  26. end