From ab2ef63a035767c587c46aa5820f7291ac033641 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 22 Feb 2024 05:39:18 -0500 Subject: [PATCH] Add basic coverage for `VoteService` class (#29334) --- spec/services/vote_service_spec.rb | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 spec/services/vote_service_spec.rb diff --git a/spec/services/vote_service_spec.rb b/spec/services/vote_service_spec.rb new file mode 100644 index 00000000000..88207b001c3 --- /dev/null +++ b/spec/services/vote_service_spec.rb @@ -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