2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-06 12:51:56 +11:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-03 02:58:48 +10:00
|
|
|
RSpec.describe MuteService, type: :service do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject { described_class.new.call(account, target_account) }
|
2017-05-07 00:31:07 +10:00
|
|
|
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:target_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
describe 'home timeline' do
|
|
|
|
let(:status) { Fabricate(:status, account: target_account) }
|
|
|
|
let(:other_account_status) { Fabricate(:status) }
|
|
|
|
let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
|
|
|
|
|
|
|
|
before do
|
2022-04-29 01:47:34 +10:00
|
|
|
redis.del(home_timeline_key)
|
2017-05-07 00:31:07 +10:00
|
|
|
end
|
|
|
|
|
2024-01-10 22:06:58 +11:00
|
|
|
it "clears account's statuses", :sidekiq_inline do
|
2017-11-18 10:16:48 +11:00
|
|
|
FeedManager.instance.push_to_home(account, status)
|
|
|
|
FeedManager.instance.push_to_home(account, other_account_status)
|
2017-05-07 00:31:07 +10:00
|
|
|
|
2022-03-28 21:43:58 +11:00
|
|
|
expect { subject }.to change {
|
2022-04-29 01:47:34 +10:00
|
|
|
redis.zrange(home_timeline_key, 0, -1)
|
2017-05-07 00:31:07 +10:00
|
|
|
}.from([status.id.to_s, other_account_status.id.to_s]).to([other_account_status.id.to_s])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'mutes account' do
|
2022-03-28 21:43:58 +11:00
|
|
|
expect { subject }.to change {
|
2017-05-07 00:31:07 +10:00
|
|
|
account.muting?(target_account)
|
|
|
|
}.from(false).to(true)
|
|
|
|
end
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
context 'without specifying a notifications parameter' do
|
|
|
|
it 'mutes notifications from the account' do
|
2022-03-28 21:43:58 +11:00
|
|
|
expect { subject }.to change {
|
2017-11-15 13:56:41 +11:00
|
|
|
account.muting_notifications?(target_account)
|
|
|
|
}.from(false).to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a true notifications parameter' do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject { described_class.new.call(account, target_account, notifications: true) }
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
it 'mutes notifications from the account' do
|
2022-03-28 21:43:58 +11:00
|
|
|
expect { subject }.to change {
|
2017-11-15 13:56:41 +11:00
|
|
|
account.muting_notifications?(target_account)
|
|
|
|
}.from(false).to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a false notifications parameter' do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject { described_class.new.call(account, target_account, notifications: false) }
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
it 'does not mute notifications from the account' do
|
2022-03-28 21:43:58 +11:00
|
|
|
expect { subject }.to_not change {
|
2017-11-15 13:56:41 +11:00
|
|
|
account.muting_notifications?(target_account)
|
|
|
|
}.from(false)
|
|
|
|
end
|
|
|
|
end
|
2017-02-06 12:51:56 +11:00
|
|
|
end
|