2023-02-21 16:55:31 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-13 13:15:32 -07:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Web::PushSubscription, type: :model do
|
2023-02-19 20:24:14 -08:00
|
|
|
subject { described_class.new(data: data) }
|
|
|
|
|
2021-04-14 20:00:25 -07:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
let(:policy) { 'all' }
|
|
|
|
|
|
|
|
let(:data) do
|
|
|
|
{
|
|
|
|
policy: policy,
|
|
|
|
|
|
|
|
alerts: {
|
|
|
|
mention: true,
|
|
|
|
reblog: false,
|
|
|
|
follow: true,
|
|
|
|
follow_request: false,
|
|
|
|
favourite: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2017-07-13 13:15:32 -07:00
|
|
|
describe '#pushable?' do
|
2021-04-14 20:00:25 -07:00
|
|
|
let(:notification_type) { :mention }
|
|
|
|
let(:notification) { Fabricate(:notification, account: account, type: notification_type) }
|
|
|
|
|
|
|
|
%i(mention reblog follow follow_request favourite).each do |type|
|
|
|
|
context "when notification is a #{type}" do
|
|
|
|
let(:notification_type) { type }
|
|
|
|
|
2023-02-18 14:38:14 -08:00
|
|
|
it 'returns boolean corresponding to alert setting' do
|
2021-04-14 20:00:25 -07:00
|
|
|
expect(subject.pushable?(notification)).to eq data[:alerts][type]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when policy is all' do
|
|
|
|
let(:policy) { 'all' }
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-19 21:14:50 -08:00
|
|
|
expect(subject.pushable?(notification)).to be true
|
2021-04-14 20:00:25 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when policy is none' do
|
|
|
|
let(:policy) { 'none' }
|
|
|
|
|
|
|
|
it 'returns false' do
|
2023-02-19 21:14:50 -08:00
|
|
|
expect(subject.pushable?(notification)).to be false
|
2021-04-14 20:00:25 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when policy is followed' do
|
|
|
|
let(:policy) { 'followed' }
|
|
|
|
|
2023-05-03 20:49:08 -07:00
|
|
|
context 'when notification is from someone you follow' do
|
2021-04-14 20:00:25 -07:00
|
|
|
before do
|
|
|
|
account.follow!(notification.from_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-19 21:14:50 -08:00
|
|
|
expect(subject.pushable?(notification)).to be true
|
2021-04-14 20:00:25 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 20:49:08 -07:00
|
|
|
context 'when notification is not from someone you follow' do
|
2021-04-14 20:00:25 -07:00
|
|
|
it 'returns false' do
|
2023-02-19 21:14:50 -08:00
|
|
|
expect(subject.pushable?(notification)).to be false
|
2021-04-14 20:00:25 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when policy is follower' do
|
|
|
|
let(:policy) { 'follower' }
|
|
|
|
|
2023-05-03 20:49:08 -07:00
|
|
|
context 'when notification is from someone who follows you' do
|
2021-04-14 20:00:25 -07:00
|
|
|
before do
|
|
|
|
notification.from_account.follow!(account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-19 21:14:50 -08:00
|
|
|
expect(subject.pushable?(notification)).to be true
|
2021-04-14 20:00:25 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 20:49:08 -07:00
|
|
|
context 'when notification is not from someone who follows you' do
|
2021-04-14 20:00:25 -07:00
|
|
|
it 'returns false' do
|
2023-02-19 21:14:50 -08:00
|
|
|
expect(subject.pushable?(notification)).to be false
|
2021-04-14 20:00:25 -07:00
|
|
|
end
|
|
|
|
end
|
2017-07-13 13:15:32 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|