poll_expiration_notify_worker_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe PollExpirationNotifyWorker do
  4. let(:worker) { described_class.new }
  5. let(:account) { Fabricate(:account, domain: remote? ? 'example.com' : nil) }
  6. let(:status) { Fabricate(:status, account: account) }
  7. let(:poll) { Fabricate(:poll, status: status, account: account) }
  8. let(:remote?) { false }
  9. let(:poll_vote) { Fabricate(:poll_vote, poll: poll) }
  10. describe '#perform' do
  11. it 'runs without error for missing record' do
  12. expect { worker.perform(nil) }.to_not raise_error
  13. end
  14. context 'when poll is not expired' do
  15. it 'requeues job' do
  16. worker.perform(poll.id)
  17. expect(described_class.sidekiq_options_hash['lock']).to be :until_executing
  18. expect(described_class).to have_enqueued_sidekiq_job(poll.id).at(poll.expires_at + 5.minutes)
  19. end
  20. end
  21. context 'when poll is expired' do
  22. before do
  23. poll_vote
  24. travel_to poll.expires_at + 5.minutes
  25. worker.perform(poll.id)
  26. end
  27. context 'when poll is local' do
  28. it 'notifies voters' do
  29. expect(ActivityPub::DistributePollUpdateWorker).to have_enqueued_sidekiq_job(poll.status.id)
  30. end
  31. it 'notifies owner' do
  32. expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(poll.account.id, poll.id, 'Poll', 'poll')
  33. end
  34. it 'notifies local voters' do
  35. expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(poll_vote.account.id, poll.id, 'Poll', 'poll')
  36. end
  37. end
  38. context 'when poll is remote' do
  39. let(:remote?) { true }
  40. it 'does not notify remote voters' do
  41. expect(ActivityPub::DistributePollUpdateWorker).to_not have_enqueued_sidekiq_job(poll.status.id)
  42. end
  43. it 'does not notify owner' do
  44. expect(LocalNotificationWorker).to_not have_enqueued_sidekiq_job(poll.account.id, poll.id, 'Poll', 'poll')
  45. end
  46. it 'notifies local voters' do
  47. expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(poll_vote.account.id, poll.id, 'Poll', 'poll')
  48. end
  49. end
  50. end
  51. end
  52. end