2023-02-21 16:55:31 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-11 08:13:43 -07:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-01-10 03:06:58 -08:00
|
|
|
RSpec.describe RemoveStatusService, :sidekiq_inline, type: :service do
|
2023-06-06 04:58:33 -07:00
|
|
|
subject { described_class.new }
|
2017-06-11 08:13:43 -07:00
|
|
|
|
2022-01-27 15:46:42 -08:00
|
|
|
let!(:alice) { Fabricate(:account) }
|
2021-05-07 10:32:58 -07:00
|
|
|
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
2017-06-11 08:13:43 -07:00
|
|
|
let!(:jeff) { Fabricate(:account) }
|
2017-08-12 15:44:41 -07:00
|
|
|
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
2017-08-28 12:38:59 -07:00
|
|
|
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
|
2017-06-11 08:13:43 -07:00
|
|
|
|
|
|
|
before do
|
2023-12-21 06:23:53 -08:00
|
|
|
stub_request(:post, hank.inbox_url).to_return(status: 200)
|
|
|
|
stub_request(:post, bill.inbox_url).to_return(status: 200)
|
2017-06-11 08:13:43 -07:00
|
|
|
|
|
|
|
jeff.follow!(alice)
|
2017-08-12 15:44:41 -07:00
|
|
|
hank.follow!(alice)
|
2017-06-11 08:13:43 -07:00
|
|
|
end
|
|
|
|
|
2022-02-11 05:52:07 -08:00
|
|
|
context 'when removed status is not a reblog' do
|
2024-01-09 01:40:08 -08:00
|
|
|
let!(:media_attachment) { Fabricate(:media_attachment, account: alice) }
|
|
|
|
let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret", media_ids: [media_attachment.id]) }
|
2023-11-08 07:42:30 -08:00
|
|
|
|
2022-02-11 05:52:07 -08:00
|
|
|
before do
|
2023-11-08 07:42:30 -08:00
|
|
|
FavouriteService.new.call(jeff, status)
|
|
|
|
Fabricate(:status, account: bill, reblog: status, uri: 'hoge')
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
2017-06-11 08:13:43 -07:00
|
|
|
|
2022-02-11 05:52:07 -08:00
|
|
|
it 'removes status from author\'s home feed' do
|
2023-11-08 07:42:30 -08:00
|
|
|
subject.call(status)
|
|
|
|
expect(HomeFeed.new(alice).get(10).pluck(:id)).to_not include(status.id)
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes status from local follower\'s home feed' do
|
2023-11-08 07:42:30 -08:00
|
|
|
subject.call(status)
|
|
|
|
expect(HomeFeed.new(jeff).get(10).pluck(:id)).to_not include(status.id)
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
2017-06-11 08:13:43 -07:00
|
|
|
|
2024-01-09 01:40:08 -08:00
|
|
|
it 'publishes to public media timeline' do
|
|
|
|
allow(redis).to receive(:publish).with(any_args)
|
|
|
|
|
|
|
|
subject.call(status)
|
|
|
|
|
|
|
|
expect(redis).to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s))
|
|
|
|
end
|
|
|
|
|
2022-02-11 05:52:07 -08:00
|
|
|
it 'sends Delete activity to followers' do
|
2023-11-08 07:42:30 -08:00
|
|
|
subject.call(status)
|
2023-12-21 06:23:53 -08:00
|
|
|
expect(a_request(:post, hank.inbox_url).with(
|
2023-02-17 13:56:20 -08:00
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Delete',
|
|
|
|
'object' => {
|
|
|
|
'type' => 'Tombstone',
|
2023-11-08 07:42:30 -08:00
|
|
|
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
|
|
|
'atomUri' => OStatus::TagManager.instance.uri_for(status),
|
2023-02-17 13:56:20 -08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends Delete activity to rebloggers' do
|
2023-11-08 07:42:30 -08:00
|
|
|
subject.call(status)
|
2023-12-21 06:23:53 -08:00
|
|
|
expect(a_request(:post, bill.inbox_url).with(
|
2023-02-17 13:56:20 -08:00
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Delete',
|
|
|
|
'object' => {
|
|
|
|
'type' => 'Tombstone',
|
2023-11-08 07:42:30 -08:00
|
|
|
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
|
|
|
'atomUri' => OStatus::TagManager.instance.uri_for(status),
|
2023-02-17 13:56:20 -08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'remove status from notifications' do
|
2023-11-08 07:42:30 -08:00
|
|
|
expect { subject.call(status) }.to change {
|
2022-02-11 05:52:07 -08:00
|
|
|
Notification.where(activity_type: 'Favourite', from_account: jeff, account: alice).count
|
|
|
|
}.from(1).to(0)
|
|
|
|
end
|
2017-08-12 15:44:41 -07:00
|
|
|
end
|
|
|
|
|
2022-02-11 05:52:07 -08:00
|
|
|
context 'when removed status is a private self-reblog' do
|
2023-11-08 07:42:30 -08:00
|
|
|
let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :private) }
|
|
|
|
let!(:status) { ReblogService.new.call(alice, original_status) }
|
2022-02-11 05:52:07 -08:00
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
2023-11-08 07:42:30 -08:00
|
|
|
subject.call(status)
|
2023-12-21 06:23:53 -08:00
|
|
|
expect(a_request(:post, hank.inbox_url).with(
|
2023-02-17 13:56:20 -08:00
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Undo',
|
|
|
|
'object' => hash_including({
|
|
|
|
'type' => 'Announce',
|
2023-11-08 07:42:30 -08:00
|
|
|
'object' => ActivityPub::TagManager.instance.uri_for(original_status),
|
2023-02-17 13:56:20 -08:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
2017-08-28 12:38:59 -07:00
|
|
|
end
|
2020-12-21 09:22:17 -08:00
|
|
|
|
2022-02-11 05:52:07 -08:00
|
|
|
context 'when removed status is public self-reblog' do
|
2023-11-08 07:42:30 -08:00
|
|
|
let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :public) }
|
|
|
|
let!(:status) { ReblogService.new.call(alice, original_status) }
|
2022-02-11 05:52:07 -08:00
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
2023-11-08 07:42:30 -08:00
|
|
|
subject.call(status)
|
2023-12-21 06:23:53 -08:00
|
|
|
expect(a_request(:post, hank.inbox_url).with(
|
2023-02-17 13:56:20 -08:00
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Undo',
|
|
|
|
'object' => hash_including({
|
|
|
|
'type' => 'Announce',
|
2023-11-08 07:42:30 -08:00
|
|
|
'object' => ActivityPub::TagManager.instance.uri_for(original_status),
|
2023-02-17 13:56:20 -08:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
2022-02-11 05:52:07 -08:00
|
|
|
end
|
2020-12-21 09:22:17 -08:00
|
|
|
end
|
2017-06-11 08:13:43 -07:00
|
|
|
end
|