From 814a48517fe820db9a606ba8274c104f002678d9 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 21 Mar 2024 17:46:38 +0100 Subject: [PATCH] Add some more tests for notification policies (#29698) --- .../api/v1/notifications/policies_spec.rb | 29 ++++++++++++++++--- .../api/v1/notifications/requests_spec.rb | 7 +---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/spec/requests/api/v1/notifications/policies_spec.rb b/spec/requests/api/v1/notifications/policies_spec.rb index fe6bdbd97..9acd47a7b 100644 --- a/spec/requests/api/v1/notifications/policies_spec.rb +++ b/spec/requests/api/v1/notifications/policies_spec.rb @@ -22,10 +22,20 @@ RSpec.describe 'Policies' do it_behaves_like 'forbidden for wrong scope', 'write write:notifications' context 'with no options' do - it 'returns http success', :aggregate_failures do + it 'returns json with expected attributes', :aggregate_failures do subject expect(response).to have_http_status(200) + 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( + pending_requests_count: '1', + pending_notifications_count: '0' + ) + ) end end end @@ -35,14 +45,25 @@ RSpec.describe 'Policies' do put '/api/v1/notifications/policy', headers: headers, params: params end - let(:params) { {} } + let(:params) { { filter_not_following: true } } it_behaves_like 'forbidden for wrong scope', 'read read:notifications' - it 'returns http success' do - subject + it 'changes notification policy and returns an updated json object', :aggregate_failures do + expect { subject } + .to change { NotificationPolicy.find_or_initialize_by(account: user.account).filter_not_following }.from(false).to(true) expect(response).to have_http_status(200) + 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( + pending_requests_count: '0', + pending_notifications_count: '0' + ) + ) end end end diff --git a/spec/requests/api/v1/notifications/requests_spec.rb b/spec/requests/api/v1/notifications/requests_spec.rb index 64675d562..772402a6b 100644 --- a/spec/requests/api/v1/notifications/requests_spec.rb +++ b/spec/requests/api/v1/notifications/requests_spec.rb @@ -82,15 +82,10 @@ RSpec.describe 'Requests' do it_behaves_like 'forbidden for wrong scope', 'read read:notifications' - it 'returns http success' do + it 'returns http success and dismisses the notification request', :aggregate_failures do subject expect(response).to have_http_status(200) - end - - it 'dismisses the notification request' do - subject - expect(notification_request.reload.dismissed?).to be true end