2018-03-04 03:19:11 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ActivityPub::Activity::Add do
|
2022-01-16 18:49:55 -05:00
|
|
|
let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured', domain: 'example.com') }
|
|
|
|
let(:status) { Fabricate(:status, account: sender, visibility: :private) }
|
2018-03-04 03:19:11 -05:00
|
|
|
|
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Add',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
object: ActivityPub::TagManager.instance.uri_for(status),
|
|
|
|
target: sender.featured_collection_url,
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
subject { described_class.new(json, sender) }
|
|
|
|
|
2018-05-18 05:33:56 -04:00
|
|
|
it 'creates a pin' do
|
2018-03-04 03:19:11 -05:00
|
|
|
subject.perform
|
2018-05-18 05:33:56 -04:00
|
|
|
expect(sender.pinned?(status)).to be true
|
2018-03-04 03:19:11 -05:00
|
|
|
end
|
|
|
|
|
2018-05-18 05:33:56 -04:00
|
|
|
context 'when status was not known before' do
|
2022-01-16 18:49:55 -05:00
|
|
|
let(:service_stub) { double }
|
|
|
|
|
2018-05-18 05:33:56 -04:00
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Add',
|
|
|
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
|
|
object: 'https://example.com/unknown',
|
|
|
|
target: sender.featured_collection_url,
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2022-01-16 18:49:55 -05:00
|
|
|
allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service_stub)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a local follower' do
|
|
|
|
before do
|
|
|
|
account = Fabricate(:account)
|
|
|
|
account.follow!(sender)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fetches the status and pins it' do
|
2023-02-19 20:45:50 -05:00
|
|
|
allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, request_id: nil| # rubocop:disable Lint/UnusedBlockArgument
|
2022-01-16 18:49:55 -05:00
|
|
|
expect(uri).to eq 'https://example.com/unknown'
|
|
|
|
expect(id).to eq true
|
|
|
|
expect(on_behalf_of&.following?(sender)).to eq true
|
|
|
|
status
|
|
|
|
end
|
|
|
|
subject.perform
|
|
|
|
expect(service_stub).to have_received(:call)
|
|
|
|
expect(sender.pinned?(status)).to be true
|
|
|
|
end
|
2018-05-18 05:33:56 -04:00
|
|
|
end
|
|
|
|
|
2022-01-16 18:49:55 -05:00
|
|
|
context 'when there is no local follower' do
|
|
|
|
it 'tries to fetch the status' do
|
2023-02-19 20:45:50 -05:00
|
|
|
allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, request_id: nil| # rubocop:disable Lint/UnusedBlockArgument
|
2022-01-16 18:49:55 -05:00
|
|
|
expect(uri).to eq 'https://example.com/unknown'
|
|
|
|
expect(id).to eq true
|
|
|
|
expect(on_behalf_of).to eq nil
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
subject.perform
|
|
|
|
expect(service_stub).to have_received(:call)
|
|
|
|
expect(sender.pinned?(status)).to be false
|
|
|
|
end
|
2018-05-18 05:33:56 -04:00
|
|
|
end
|
2018-03-04 03:19:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|