2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-19 22:13:47 +11:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-13 19:39:26 +11:00
|
|
|
RSpec.describe FanOutOnWriteService do
|
2023-02-20 15:24:14 +11:00
|
|
|
subject { described_class.new }
|
|
|
|
|
2022-01-20 08:37:27 +11:00
|
|
|
let(:last_active_at) { Time.now.utc }
|
2023-12-12 21:39:21 +11:00
|
|
|
let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob @eve #hoge') }
|
2016-11-07 01:56:34 +11:00
|
|
|
|
2022-01-28 10:46:42 +11:00
|
|
|
let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
|
|
|
let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
|
|
|
|
let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
2023-12-12 21:39:21 +11:00
|
|
|
let!(:eve) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'eve' }).account }
|
2022-01-20 08:37:27 +11:00
|
|
|
|
2016-11-07 01:56:34 +11:00
|
|
|
before do
|
2022-01-20 08:37:27 +11:00
|
|
|
bob.follow!(alice)
|
|
|
|
tom.follow!(alice)
|
2016-11-07 01:56:34 +11:00
|
|
|
|
|
|
|
ProcessMentionsService.new.call(status)
|
|
|
|
ProcessHashtagsService.new.call(status)
|
|
|
|
|
2024-01-09 20:40:08 +11:00
|
|
|
Fabricate(:media_attachment, status: status, account: alice)
|
|
|
|
|
2022-04-29 01:47:34 +10:00
|
|
|
allow(redis).to receive(:publish)
|
2022-01-20 08:37:27 +11:00
|
|
|
|
2016-11-07 01:56:34 +11:00
|
|
|
subject.call(status)
|
|
|
|
end
|
|
|
|
|
2022-01-20 08:37:27 +11:00
|
|
|
def home_feed_of(account)
|
|
|
|
HomeFeed.new(account).get(10).map(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when status is public' do
|
|
|
|
let(:visibility) { 'public' }
|
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
it 'adds status to home feed of author and followers and broadcasts', :inline_jobs do
|
|
|
|
expect(status.id)
|
|
|
|
.to be_in(home_feed_of(alice))
|
|
|
|
.and be_in(home_feed_of(bob))
|
|
|
|
.and be_in(home_feed_of(tom))
|
2022-01-20 08:37:27 +11:00
|
|
|
|
2022-04-29 01:47:34 +10:00
|
|
|
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything)
|
|
|
|
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
|
|
|
|
expect(redis).to have_received(:publish).with('timeline:public', anything)
|
|
|
|
expect(redis).to have_received(:publish).with('timeline:public:local', anything)
|
2024-01-09 20:40:08 +11:00
|
|
|
expect(redis).to have_received(:publish).with('timeline:public:media', anything)
|
2022-01-20 08:37:27 +11:00
|
|
|
end
|
2016-11-07 01:56:34 +11:00
|
|
|
end
|
|
|
|
|
2022-01-20 08:37:27 +11:00
|
|
|
context 'when status is limited' do
|
|
|
|
let(:visibility) { 'limited' }
|
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
it 'adds status to home feed of author and mentioned followers and does not broadcast', :inline_jobs do
|
|
|
|
expect(status.id)
|
|
|
|
.to be_in(home_feed_of(alice))
|
|
|
|
.and be_in(home_feed_of(bob))
|
|
|
|
expect(status.id)
|
|
|
|
.to_not be_in(home_feed_of(tom))
|
2022-01-20 08:37:27 +11:00
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
expect_no_broadcasting
|
2022-01-20 08:37:27 +11:00
|
|
|
end
|
2016-11-07 01:56:34 +11:00
|
|
|
end
|
|
|
|
|
2022-01-20 08:37:27 +11:00
|
|
|
context 'when status is private' do
|
|
|
|
let(:visibility) { 'private' }
|
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
it 'adds status to home feed of author and followers and does not broadcast', :inline_jobs do
|
|
|
|
expect(status.id)
|
|
|
|
.to be_in(home_feed_of(alice))
|
|
|
|
.and be_in(home_feed_of(bob))
|
|
|
|
.and be_in(home_feed_of(tom))
|
2022-01-20 08:37:27 +11:00
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
expect_no_broadcasting
|
2022-01-20 08:37:27 +11:00
|
|
|
end
|
2016-11-07 01:56:34 +11:00
|
|
|
end
|
|
|
|
|
2022-01-20 08:37:27 +11:00
|
|
|
context 'when status is direct' do
|
|
|
|
let(:visibility) { 'direct' }
|
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
it 'is added to the home feed of its author and mentioned followers and does not broadcast', :inline_jobs do
|
|
|
|
expect(status.id)
|
|
|
|
.to be_in(home_feed_of(alice))
|
|
|
|
.and be_in(home_feed_of(bob))
|
|
|
|
expect(status.id)
|
|
|
|
.to_not be_in(home_feed_of(tom))
|
2022-01-20 08:37:27 +11:00
|
|
|
|
2024-07-18 17:45:59 +10:00
|
|
|
expect_no_broadcasting
|
2022-01-20 08:37:27 +11:00
|
|
|
end
|
2023-12-12 21:39:21 +11:00
|
|
|
|
2024-01-10 22:06:58 +11:00
|
|
|
context 'when handling status updates' do
|
2023-12-12 21:39:21 +11:00
|
|
|
before do
|
|
|
|
subject.call(status)
|
|
|
|
|
|
|
|
status.snapshot!(at_time: status.created_at, rate_limit: false)
|
|
|
|
status.update!(text: 'Hello @bob @eve #hoge (edited)')
|
|
|
|
status.snapshot!(account_id: status.account_id)
|
|
|
|
|
|
|
|
redis.set("subscribed:timeline:#{eve.id}:notifications", '1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'pushes the update to mentioned users through the notifications streaming channel' do
|
|
|
|
subject.call(status, update: true)
|
|
|
|
expect(PushUpdateWorker).to have_enqueued_sidekiq_job(anything, status.id, "timeline:#{eve.id}:notifications", { 'update' => true })
|
|
|
|
end
|
|
|
|
end
|
2016-11-07 01:56:34 +11:00
|
|
|
end
|
2024-07-18 17:45:59 +10:00
|
|
|
|
|
|
|
def expect_no_broadcasting
|
|
|
|
expect(redis)
|
|
|
|
.to_not have_received(:publish)
|
|
|
|
.with('timeline:hashtag:hoge', anything)
|
|
|
|
expect(redis)
|
|
|
|
.to_not have_received(:publish)
|
|
|
|
.with('timeline:public', anything)
|
|
|
|
end
|
2016-03-19 22:13:47 +11:00
|
|
|
end
|