1
0

vote_service_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe VoteService do
  4. describe '#call' do
  5. subject { described_class.new.call(voter, poll, [0]) }
  6. context 'with a poll and poll options' do
  7. let(:poll) { Fabricate(:poll, account: account, options: %w(Fun UnFun)) }
  8. let(:fun_vote) { Fabricate(:poll_vote, poll: poll) }
  9. let(:not_fun_vote) { Fabricate(:poll_vote, poll: poll) }
  10. let(:voter) { Fabricate(:account, domain: nil) }
  11. context 'when the poll was created by a local account' do
  12. let(:account) { Fabricate(:account, domain: nil) }
  13. it 'stores the votes and distributes the poll' do
  14. expect { subject }
  15. .to change(PollVote, :count).by(1)
  16. expect(ActivityPub::DistributePollUpdateWorker)
  17. .to have_enqueued_sidekiq_job(poll.status.id)
  18. end
  19. end
  20. context 'when the poll was created by a remote account' do
  21. let(:account) { Fabricate(:account, domain: 'host.example') }
  22. it 'stores the votes and processes delivery' do
  23. expect { subject }
  24. .to change(PollVote, :count).by(1)
  25. expect(ActivityPub::DeliveryWorker)
  26. .to have_enqueued_sidekiq_job(anything, voter.id, poll.account.inbox_url)
  27. end
  28. end
  29. end
  30. end
  31. end