0
0
Fork 0

Reload notifications when accepted notifications are merged (streaming only) (#31419)

This commit is contained in:
Claire 2024-08-19 17:59:06 +02:00 committed by GitHub
parent d4f135bc6d
commit 53c183f899
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 192 additions and 24 deletions

View file

@ -13,13 +13,56 @@ describe UnfilterNotificationsWorker do
Fabricate(:notification, filtered: true, from_account: sender, account: recipient, type: :mention, activity: mention)
follow_request = sender.request_follow!(recipient)
Fabricate(:notification, filtered: true, from_account: sender, account: recipient, type: :follow_request, activity: follow_request)
allow(redis).to receive(:publish)
allow(redis).to receive(:exists?).and_return(false)
end
shared_examples 'shared behavior' do
it 'unfilters notifications and adds private messages to conversations' do
expect { subject }
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
context 'when this is the last pending merge job and the user is subscribed to streaming' do
before do
redis.set("notification_unfilter_jobs:#{recipient.id}", 1)
allow(redis).to receive(:exists?).with("subscribed:timeline:#{recipient.id}").and_return(true)
end
it 'unfilters notifications, adds private messages to conversations, and pushes to redis' do
expect { subject }
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
.and change { redis.get("notification_unfilter_jobs:#{recipient.id}").to_i }.by(-1)
expect(redis).to have_received(:publish).with("timeline:#{recipient.id}:notifications", '{"event":"notifications_merged","payload":"1"}')
end
end
context 'when this is not last pending merge job and the user is subscribed to streaming' do
before do
redis.set("notification_unfilter_jobs:#{recipient.id}", 2)
allow(redis).to receive(:exists?).with("subscribed:timeline:#{recipient.id}").and_return(true)
end
it 'unfilters notifications, adds private messages to conversations, and does not push to redis' do
expect { subject }
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
.and change { redis.get("notification_unfilter_jobs:#{recipient.id}").to_i }.by(-1)
expect(redis).to_not have_received(:publish).with("timeline:#{recipient.id}:notifications", '{"event":"notifications_merged","payload":"1"}')
end
end
context 'when this is the last pending merge job and the user is not subscribed to streaming' do
before do
redis.set("notification_unfilter_jobs:#{recipient.id}", 1)
end
it 'unfilters notifications, adds private messages to conversations, and does not push to redis' do
expect { subject }
.to change { recipient.notifications.where(from_account_id: sender.id).pluck(:filtered) }.from([true, true]).to([false, false])
.and change { recipient.conversations.exists?(last_status_id: sender.statuses.first.id) }.to(true)
.and change { redis.get("notification_unfilter_jobs:#{recipient.id}").to_i }.by(-1)
expect(redis).to_not have_received(:publish).with("timeline:#{recipient.id}:notifications", '{"event":"notifications_merged","payload":"1"}')
end
end
end