Add `policy` param to `POST /api/v1/push/subscriptions` (#16040)
With possible values `all`, `followed`, `follower`, and `none`, control from whom notifications will generate a Web Push alertmaster
parent
c968d22ee9
commit
ce2148c571
@ -1,16 +1,94 @@ |
|||||||
require 'rails_helper' |
require 'rails_helper' |
||||||
|
|
||||||
RSpec.describe Web::PushSubscription, type: :model do |
RSpec.describe Web::PushSubscription, type: :model do |
||||||
let(:alerts) { { mention: true, reblog: false, follow: true, follow_request: false, favourite: true } } |
let(:account) { Fabricate(:account) } |
||||||
let(:push_subscription) { Web::PushSubscription.new(data: { alerts: alerts }) } |
|
||||||
|
let(:policy) { 'all' } |
||||||
|
|
||||||
|
let(:data) do |
||||||
|
{ |
||||||
|
policy: policy, |
||||||
|
|
||||||
|
alerts: { |
||||||
|
mention: true, |
||||||
|
reblog: false, |
||||||
|
follow: true, |
||||||
|
follow_request: false, |
||||||
|
favourite: true, |
||||||
|
}, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
subject { described_class.new(data: data) } |
||||||
|
|
||||||
describe '#pushable?' do |
describe '#pushable?' do |
||||||
it 'obeys alert settings' do |
let(:notification_type) { :mention } |
||||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Mention'))).to eq true |
let(:notification) { Fabricate(:notification, account: account, type: notification_type) } |
||||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Status'))).to eq false |
|
||||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Follow'))).to eq true |
%i(mention reblog follow follow_request favourite).each do |type| |
||||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'FollowRequest'))).to eq false |
context "when notification is a #{type}" do |
||||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Favourite'))).to eq true |
let(:notification_type) { type } |
||||||
|
|
||||||
|
it "returns boolean corresonding to alert setting" do |
||||||
|
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 |
||||||
|
expect(subject.pushable?(notification)).to eq true |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'when policy is none' do |
||||||
|
let(:policy) { 'none' } |
||||||
|
|
||||||
|
it 'returns false' do |
||||||
|
expect(subject.pushable?(notification)).to eq false |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'when policy is followed' do |
||||||
|
let(:policy) { 'followed' } |
||||||
|
|
||||||
|
context 'and notification is from someone you follow' do |
||||||
|
before do |
||||||
|
account.follow!(notification.from_account) |
||||||
|
end |
||||||
|
|
||||||
|
it 'returns true' do |
||||||
|
expect(subject.pushable?(notification)).to eq true |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'and notification is not from someone you follow' do |
||||||
|
it 'returns false' do |
||||||
|
expect(subject.pushable?(notification)).to eq false |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'when policy is follower' do |
||||||
|
let(:policy) { 'follower' } |
||||||
|
|
||||||
|
context 'and notification is from someone who follows you' do |
||||||
|
before do |
||||||
|
notification.from_account.follow!(account) |
||||||
|
end |
||||||
|
|
||||||
|
it 'returns true' do |
||||||
|
expect(subject.pushable?(notification)).to eq true |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'and notification is not from someone who follows you' do |
||||||
|
it 'returns false' do |
||||||
|
expect(subject.pushable?(notification)).to eq false |
||||||
|
end |
||||||
|
end |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue