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