poll_expiration_notify_worker_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. 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. around do |example|
  12. Sidekiq::Testing.fake! do
  13. example.run
  14. end
  15. end
  16. it 'runs without error for missing record' do
  17. expect { worker.perform(nil) }.to_not raise_error
  18. end
  19. context 'when poll is not expired' do
  20. it 'requeues job' do
  21. worker.perform(poll.id)
  22. expect(described_class.sidekiq_options_hash['lock']).to be :until_executing
  23. expect(described_class).to have_enqueued_sidekiq_job(poll.id).at(poll.expires_at + 5.minutes)
  24. end
  25. end
  26. context 'when poll is expired' do
  27. before do
  28. poll_vote
  29. travel_to poll.expires_at + 5.minutes
  30. worker.perform(poll.id)
  31. end
  32. context 'when poll is local' do
  33. it 'notifies voters' do
  34. expect(ActivityPub::DistributePollUpdateWorker).to have_enqueued_sidekiq_job(poll.status.id)
  35. end
  36. it 'notifies owner' do
  37. expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(poll.account.id, poll.id, 'Poll', 'poll')
  38. end
  39. it 'notifies local voters' do
  40. expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(poll_vote.account.id, poll.id, 'Poll', 'poll')
  41. end
  42. end
  43. context 'when poll is remote' do
  44. let(:remote?) { true }
  45. it 'does not notify remote voters' do
  46. expect(ActivityPub::DistributePollUpdateWorker).to_not have_enqueued_sidekiq_job(poll.status.id)
  47. end
  48. it 'does not notify owner' do
  49. expect(LocalNotificationWorker).to_not have_enqueued_sidekiq_job(poll.account.id, poll.id, 'Poll', 'poll')
  50. end
  51. it 'notifies local voters' do
  52. expect(LocalNotificationWorker).to have_enqueued_sidekiq_job(poll_vote.account.id, poll.id, 'Poll', 'poll')
  53. end
  54. end
  55. end
  56. end
  57. end