mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-23 00:30:57 +01:00
Add basic coverage for VoteService
class (#29334)
This commit is contained in:
parent
fa1c3a0915
commit
ab2ef63a03
1 changed files with 40 additions and 0 deletions
40
spec/services/vote_service_spec.rb
Normal file
40
spec/services/vote_service_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe VoteService do
|
||||||
|
describe '#call' do
|
||||||
|
subject { described_class.new.call(voter, poll, [0]) }
|
||||||
|
|
||||||
|
context 'with a poll and poll options' do
|
||||||
|
let(:poll) { Fabricate(:poll, account: account, options: %w(Fun UnFun)) }
|
||||||
|
let(:fun_vote) { Fabricate(:poll_vote, poll: poll) }
|
||||||
|
let(:not_fun_vote) { Fabricate(:poll_vote, poll: poll) }
|
||||||
|
let(:voter) { Fabricate(:account, domain: nil) }
|
||||||
|
|
||||||
|
context 'when the poll was created by a local account' do
|
||||||
|
let(:account) { Fabricate(:account, domain: nil) }
|
||||||
|
|
||||||
|
it 'stores the votes and distributes the poll' do
|
||||||
|
expect { subject }
|
||||||
|
.to change(PollVote, :count).by(1)
|
||||||
|
|
||||||
|
expect(ActivityPub::DistributePollUpdateWorker)
|
||||||
|
.to have_enqueued_sidekiq_job(poll.status.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the poll was created by a remote account' do
|
||||||
|
let(:account) { Fabricate(:account, domain: 'host.example') }
|
||||||
|
|
||||||
|
it 'stores the votes and processes delivery' do
|
||||||
|
expect { subject }
|
||||||
|
.to change(PollVote, :count).by(1)
|
||||||
|
|
||||||
|
expect(ActivityPub::DeliveryWorker)
|
||||||
|
.to have_enqueued_sidekiq_job(anything, voter.id, poll.account.inbox_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue