Merge remote-tracking branch 'parent/main' into upstream-20240813
This commit is contained in:
commit
e7ccc0539f
358 changed files with 4653 additions and 4261 deletions
19
spec/services/dismiss_notification_request_service_spec.rb
Normal file
19
spec/services/dismiss_notification_request_service_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DismissNotificationRequestService do
|
||||
describe '#call' do
|
||||
let(:sender) { Fabricate(:account) }
|
||||
let(:receiver) { Fabricate(:account) }
|
||||
let(:request) { Fabricate(:notification_request, account: receiver, from_account: sender) }
|
||||
|
||||
it 'destroys the request and queues a worker', :aggregate_failures do
|
||||
expect { described_class.new.call(request) }
|
||||
.to change(request, :destroyed?).to(true)
|
||||
|
||||
expect(FilteredNotificationCleanupWorker)
|
||||
.to have_enqueued_sidekiq_job(receiver.id, sender.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -129,6 +129,40 @@ RSpec.describe NotifyService do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the blocked sender has a role' do
|
||||
let(:sender) { Fabricate(:user, role: sender_role).account }
|
||||
let(:activity) { Fabricate(:mention, status: Fabricate(:status, account: sender)) }
|
||||
let(:type) { :mention }
|
||||
|
||||
before do
|
||||
recipient.block!(sender)
|
||||
end
|
||||
|
||||
context 'when the role is a visible moderator' do
|
||||
let(:sender_role) { Fabricate(:user_role, highlighted: true, permissions: UserRole::FLAGS[:manage_users]) }
|
||||
|
||||
it 'does notify' do
|
||||
expect { subject }.to change(Notification, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the role is a non-visible moderator' do
|
||||
let(:sender_role) { Fabricate(:user_role, highlighted: false, permissions: UserRole::FLAGS[:manage_users]) }
|
||||
|
||||
it 'does not notify' do
|
||||
expect { subject }.to_not change(Notification, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the role is a visible non-moderator' do
|
||||
let(:sender_role) { Fabricate(:user_role, highlighted: true) }
|
||||
|
||||
it 'does not notify' do
|
||||
expect { subject }.to_not change(Notification, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with filtered notifications' do
|
||||
let(:unknown) { Fabricate(:account, username: 'unknown') }
|
||||
let(:status) { Fabricate(:status, account: unknown) }
|
||||
|
@ -162,20 +196,58 @@ RSpec.describe NotifyService do
|
|||
end
|
||||
end
|
||||
|
||||
describe NotifyService::DismissCondition do
|
||||
describe NotifyService::DropCondition do
|
||||
subject { described_class.new(notification) }
|
||||
|
||||
let(:activity) { Fabricate(:mention, status: Fabricate(:status)) }
|
||||
let(:notification) { Fabricate(:notification, type: :mention, activity: activity, from_account: activity.status.account, account: activity.account) }
|
||||
|
||||
describe '#dismiss?' do
|
||||
context 'when sender is silenced' do
|
||||
describe '#drop' do
|
||||
context 'when sender is silenced and recipient has a default policy' do
|
||||
before do
|
||||
notification.from_account.silence!
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject.dismiss?).to be false
|
||||
expect(subject.drop?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sender is silenced and recipient has a policy to ignore silenced accounts' do
|
||||
before do
|
||||
notification.from_account.silence!
|
||||
notification.account.create_notification_policy!(for_limited_accounts: :drop)
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.drop?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sender is new and recipient has a default policy' do
|
||||
it 'returns false' do
|
||||
expect(subject.drop?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sender is new and recipient has a policy to ignore silenced accounts' do
|
||||
before do
|
||||
notification.account.create_notification_policy!(for_new_accounts: :drop)
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.drop?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sender is new and followed and recipient has a policy to ignore silenced accounts' do
|
||||
before do
|
||||
notification.account.create_notification_policy!(for_new_accounts: :drop)
|
||||
notification.account.follow!(notification.from_account)
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject.drop?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -185,7 +257,7 @@ RSpec.describe NotifyService do
|
|||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.dismiss?).to be true
|
||||
expect(subject.drop?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -216,6 +288,16 @@ RSpec.describe NotifyService do
|
|||
expect(subject.filter?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when recipient is allowing limited accounts' do
|
||||
before do
|
||||
notification.account.create_notification_policy!(for_limited_accounts: :accept)
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject.filter?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when recipient is filtering not-followed senders' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue