2024-03-08 01:53:37 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Policies' do
|
|
|
|
let(:user) { Fabricate(:user, account_attributes: { username: 'alice' }) }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:scopes) { 'read:notifications write:notifications' }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
|
|
|
|
2024-07-09 02:01:08 +10:00
|
|
|
describe 'GET /api/v1/notifications/policy', :inline_jobs do
|
2024-03-08 01:53:37 +11:00
|
|
|
subject do
|
|
|
|
get '/api/v1/notifications/policy', headers: headers, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Fabricate(:notification_request, account: user.account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'write write:notifications'
|
|
|
|
|
|
|
|
context 'with no options' do
|
2024-03-22 03:46:38 +11:00
|
|
|
it 'returns json with expected attributes', :aggregate_failures do
|
2024-03-08 01:53:37 +11:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2024-03-22 03:46:38 +11:00
|
|
|
expect(body_as_json).to include(
|
|
|
|
filter_not_following: false,
|
|
|
|
filter_not_followers: false,
|
|
|
|
filter_new_accounts: false,
|
|
|
|
filter_private_mentions: true,
|
|
|
|
summary: a_hash_including(
|
2024-04-02 21:06:26 +11:00
|
|
|
pending_requests_count: 1,
|
|
|
|
pending_notifications_count: 0
|
2024-03-22 03:46:38 +11:00
|
|
|
)
|
|
|
|
)
|
2024-03-08 01:53:37 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /api/v1/notifications/policy' do
|
|
|
|
subject do
|
|
|
|
put '/api/v1/notifications/policy', headers: headers, params: params
|
|
|
|
end
|
|
|
|
|
2024-03-22 03:46:38 +11:00
|
|
|
let(:params) { { filter_not_following: true } }
|
2024-03-08 01:53:37 +11:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
|
|
|
|
|
2024-03-22 03:46:38 +11:00
|
|
|
it 'changes notification policy and returns an updated json object', :aggregate_failures do
|
|
|
|
expect { subject }
|
2024-08-09 23:30:55 +10:00
|
|
|
.to change { NotificationPolicy.find_or_initialize_by(account: user.account).for_not_following.to_sym }.from(:accept).to(:filter)
|
2024-03-08 01:53:37 +11:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2024-03-22 03:46:38 +11:00
|
|
|
expect(body_as_json).to include(
|
|
|
|
filter_not_following: true,
|
|
|
|
filter_not_followers: false,
|
|
|
|
filter_new_accounts: false,
|
|
|
|
filter_private_mentions: true,
|
|
|
|
summary: a_hash_including(
|
2024-04-02 21:06:26 +11:00
|
|
|
pending_requests_count: 0,
|
|
|
|
pending_notifications_count: 0
|
2024-03-22 03:46:38 +11:00
|
|
|
)
|
|
|
|
)
|
2024-03-08 01:53:37 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|