2017-06-11 15:13:43 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-02 16:58:48 +00:00
|
|
|
RSpec.describe RemoveStatusService, type: :service do
|
2017-06-11 15:13:43 +00:00
|
|
|
subject { RemoveStatusService.new }
|
|
|
|
|
2022-01-27 23:46:42 +00:00
|
|
|
let!(:alice) { Fabricate(:account) }
|
2021-05-07 17:32:58 +00:00
|
|
|
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
2017-06-11 15:13:43 +00:00
|
|
|
let!(:jeff) { Fabricate(:account) }
|
2017-08-12 22:44:41 +00:00
|
|
|
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
2017-08-28 19:38:59 +00:00
|
|
|
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
|
2017-06-11 15:13:43 +00:00
|
|
|
|
|
|
|
before do
|
2017-08-12 22:44:41 +00:00
|
|
|
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
2017-08-28 19:38:59 +00:00
|
|
|
stub_request(:post, 'http://example2.com/inbox').to_return(status: 200)
|
2017-06-11 15:13:43 +00:00
|
|
|
|
|
|
|
jeff.follow!(alice)
|
2017-08-12 22:44:41 +00:00
|
|
|
hank.follow!(alice)
|
2017-06-11 15:13:43 +00:00
|
|
|
end
|
|
|
|
|
2022-02-11 13:52:07 +00:00
|
|
|
context 'when removed status is not a reblog' do
|
|
|
|
before do
|
|
|
|
@status = PostStatusService.new.call(alice, text: 'Hello @bob@example.com ThisIsASecret')
|
|
|
|
FavouriteService.new.call(jeff, @status)
|
|
|
|
Fabricate(:status, account: bill, reblog: @status, uri: 'hoge')
|
|
|
|
end
|
2017-06-11 15:13:43 +00:00
|
|
|
|
2022-02-11 13:52:07 +00:00
|
|
|
it 'removes status from author\'s home feed' do
|
|
|
|
subject.call(@status)
|
|
|
|
expect(HomeFeed.new(alice).get(10)).to_not include(@status.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes status from local follower\'s home feed' do
|
|
|
|
subject.call(@status)
|
|
|
|
expect(HomeFeed.new(jeff).get(10)).to_not include(@status.id)
|
|
|
|
end
|
2017-06-11 15:13:43 +00:00
|
|
|
|
2022-02-11 13:52:07 +00:00
|
|
|
it 'sends Delete activity to followers' do
|
|
|
|
subject.call(@status)
|
|
|
|
expect(a_request(:post, 'http://example.com/inbox').with(
|
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Delete',
|
|
|
|
'object' => {
|
|
|
|
'type' => 'Tombstone',
|
|
|
|
'id' => ActivityPub::TagManager.instance.uri_for(@status),
|
|
|
|
'atomUri' => OStatus::TagManager.instance.uri_for(@status),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends Delete activity to rebloggers' do
|
|
|
|
subject.call(@status)
|
|
|
|
expect(a_request(:post, 'http://example2.com/inbox').with(
|
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Delete',
|
|
|
|
'object' => {
|
|
|
|
'type' => 'Tombstone',
|
|
|
|
'id' => ActivityPub::TagManager.instance.uri_for(@status),
|
|
|
|
'atomUri' => OStatus::TagManager.instance.uri_for(@status),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'remove status from notifications' do
|
|
|
|
expect { subject.call(@status) }.to change {
|
|
|
|
Notification.where(activity_type: 'Favourite', from_account: jeff, account: alice).count
|
|
|
|
}.from(1).to(0)
|
|
|
|
end
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|
|
|
|
|
2022-02-11 13:52:07 +00:00
|
|
|
context 'when removed status is a private self-reblog' do
|
|
|
|
before do
|
|
|
|
@original_status = Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :private)
|
|
|
|
@status = ReblogService.new.call(alice, @original_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
|
|
|
subject.call(@status)
|
|
|
|
expect(a_request(:post, 'http://example.com/inbox').with(
|
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Undo',
|
|
|
|
'object' => hash_including({
|
|
|
|
'type' => 'Announce',
|
|
|
|
'object' => ActivityPub::TagManager.instance.uri_for(@original_status),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
|
|
|
end
|
2017-08-28 19:38:59 +00:00
|
|
|
end
|
2020-12-21 17:22:17 +00:00
|
|
|
|
2022-02-11 13:52:07 +00:00
|
|
|
context 'when removed status is public self-reblog' do
|
|
|
|
before do
|
|
|
|
@original_status = Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :public)
|
|
|
|
@status = ReblogService.new.call(alice, @original_status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends Undo activity to followers' do
|
|
|
|
subject.call(@status)
|
|
|
|
expect(a_request(:post, 'http://example.com/inbox').with(
|
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Undo',
|
|
|
|
'object' => hash_including({
|
|
|
|
'type' => 'Announce',
|
|
|
|
'object' => ActivityPub::TagManager.instance.uri_for(@original_status),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)).to have_been_made.once
|
|
|
|
end
|
2020-12-21 17:22:17 +00:00
|
|
|
end
|
2017-06-11 15:13:43 +00:00
|
|
|
end
|