2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-14 16:01:35 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-07-08 16:01:08 +00:00
|
|
|
RSpec.describe BatchedRemoveStatusService, :inline_jobs do
|
2023-06-06 11:58:33 +00:00
|
|
|
subject { described_class.new }
|
2017-06-14 16:01:35 +00:00
|
|
|
|
|
|
|
let!(:alice) { Fabricate(:account) }
|
2021-05-07 17:32:58 +00:00
|
|
|
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
2022-01-27 23:46:42 +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-06-14 16:01:35 +00:00
|
|
|
|
2023-12-21 14:23:53 +00:00
|
|
|
let(:status_alice_hello) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct}") }
|
2023-06-14 14:44:37 +00:00
|
|
|
let(:status_alice_other) { PostStatusService.new.call(alice, text: 'Another status') }
|
2017-06-14 16:01:35 +00:00
|
|
|
|
|
|
|
before do
|
2022-04-28 15:47:34 +00:00
|
|
|
allow(redis).to receive_messages(publish: nil)
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2017-08-12 22:44:41 +00:00
|
|
|
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2018-10-08 02:50:11 +00:00
|
|
|
jeff.user.update(current_sign_in_at: Time.zone.now)
|
2017-06-14 16:01:35 +00:00
|
|
|
jeff.follow!(alice)
|
2017-08-12 22:44:41 +00:00
|
|
|
hank.follow!(alice)
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2023-06-14 14:44:37 +00:00
|
|
|
status_alice_hello
|
|
|
|
status_alice_other
|
2024-10-04 14:11:15 +00:00
|
|
|
end
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
it 'removes status records, removes from author and local follower feeds, notifies stream, sends delete' do
|
2023-06-14 14:44:37 +00:00
|
|
|
subject.call([status_alice_hello, status_alice_other])
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
expect { Status.find(status_alice_hello.id) }
|
|
|
|
.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
expect { Status.find(status_alice_other.id) }
|
|
|
|
.to raise_error ActiveRecord::RecordNotFound
|
2020-12-22 16:13:55 +00:00
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
expect(feed_ids_for(alice))
|
|
|
|
.to_not include(status_alice_hello.id, status_alice_other.id)
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
expect(feed_ids_for(jeff))
|
|
|
|
.to_not include(status_alice_hello.id, status_alice_other.id)
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
expect(redis)
|
|
|
|
.to have_received(:publish)
|
|
|
|
.with("timeline:#{jeff.id}", any_args).at_least(:once)
|
|
|
|
|
|
|
|
expect(redis)
|
|
|
|
.to have_received(:publish)
|
|
|
|
.with('timeline:public', any_args).at_least(:once)
|
2017-06-14 16:01:35 +00:00
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
expect(a_request(:post, 'http://example.com/inbox'))
|
|
|
|
.to have_been_made.at_least_once
|
2017-06-14 16:01:35 +00:00
|
|
|
end
|
|
|
|
|
2024-10-04 14:11:15 +00:00
|
|
|
def feed_ids_for(account)
|
|
|
|
HomeFeed
|
|
|
|
.new(account)
|
|
|
|
.get(10)
|
|
|
|
.pluck(:id)
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|
2017-06-14 16:01:35 +00:00
|
|
|
end
|