Skip to content

Commit

Permalink
Prep work for coverage addition to ActivityPub::DeliveryWorker spec (
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Nov 18, 2024
1 parent 30a7986 commit 295ad6f
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions spec/workers/activitypub/delivery_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,45 @@
RSpec.describe ActivityPub::DeliveryWorker do
include RoutingHelper

subject { described_class.new }

let(:sender) { Fabricate(:account) }
let(:sender) { Fabricate(:account) }
let(:payload) { 'test' }
let(:url) { 'https://example.com/api' }

before do
allow(sender).to receive(:remote_followers_hash).with('https://example.com/api').and_return('somehash')
allow(sender).to receive(:remote_followers_hash).with(url).and_return('somehash')
allow(Account).to receive(:find).with(sender.id).and_return(sender)
end

describe 'perform' do
it 'performs a request' do
stub_request(:post, 'https://example.com/api').to_return(status: 200)
subject.perform(payload, sender.id, 'https://example.com/api', { synchronize_followers: true })
expect(a_request(:post, 'https://example.com/api').with(headers: { 'Collection-Synchronization' => "collectionId=\"#{account_followers_url(sender)}\", digest=\"somehash\", url=\"#{account_followers_synchronization_url(sender)}\"" })).to have_been_made.once
context 'with successful request' do
before { stub_request(:post, url).to_return(status: 200) }

it 'performs a request to synchronize collection' do
subject.perform(payload, sender.id, url, { synchronize_followers: true })

expect(request_to_url)
.to have_been_made.once
end

def request_to_url
a_request(:post, url)
.with(
headers: {
'Collection-Synchronization' => <<~VALUES.squish,
collectionId="#{account_followers_url(sender)}", digest="somehash", url="#{account_followers_synchronization_url(sender)}"
VALUES
}
)
end
end

it 'raises when request fails' do
stub_request(:post, 'https://example.com/api').to_return(status: 500)
expect { subject.perform(payload, sender.id, 'https://example.com/api') }.to raise_error Mastodon::UnexpectedResponseError
context 'with failing request' do
before { stub_request(:post, url).to_return(status: 500) }

it 'raises error' do
expect { subject.perform(payload, sender.id, url) }
.to raise_error Mastodon::UnexpectedResponseError
end
end
end
end

0 comments on commit 295ad6f

Please sign in to comment.