From e0590511f4785045879c90efeb651ec9538eaa2d Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 1 Mar 2023 13:58:57 +0100 Subject: [PATCH] Add tests for `/api/v1/accounts/:id/*` 404 on deleted accounts --- .../follower_accounts_controller_spec.rb | 25 ++++++++++++++++ .../following_accounts_controller_spec.rb | 25 ++++++++++++++++ .../api/v1/accounts/lists_controller_spec.rb | 25 ++++++++++++++++ .../v1/accounts/statuses_controller_spec.rb | 29 +++++++++++++++++++ spec/requests/api/v1/accounts_spec.rb | 25 ++++++++++++++++ 5 files changed, 129 insertions(+) diff --git a/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb b/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb index 510a47566b371f..1ba62a0b4ddf8f 100644 --- a/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/follower_accounts_controller_spec.rb @@ -57,5 +57,30 @@ expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s) end end + + context 'when request account is permanently deleted' do + before do + account.mark_deleted! + account.deletion_request.destroy + end + + it 'returns http not found' do + get :index, params: { account_id: account.id, limit: 2 } + + expect(response).to have_http_status(404) + end + end + + context 'when request account is pending deletion' do + before do + account.mark_deleted! + end + + it 'returns http not found' do + get :index, params: { account_id: account.id, limit: 2 } + + expect(response).to have_http_status(404) + end + end end end diff --git a/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb b/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb index a7d07a6bec9a01..207a16697ccef7 100644 --- a/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/following_accounts_controller_spec.rb @@ -57,5 +57,30 @@ expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s) end end + + context 'when request account is permanently deleted' do + before do + account.mark_deleted! + account.deletion_request.destroy + end + + it 'returns http not found' do + get :index, params: { account_id: account.id, limit: 2 } + + expect(response).to have_http_status(404) + end + end + + context 'when request account is pending deletion' do + before do + account.mark_deleted! + end + + it 'returns http not found' do + get :index, params: { account_id: account.id, limit: 2 } + + expect(response).to have_http_status(404) + end + end end end diff --git a/spec/controllers/api/v1/accounts/lists_controller_spec.rb b/spec/controllers/api/v1/accounts/lists_controller_spec.rb index 418839cfa57154..8d0738db3ccddf 100644 --- a/spec/controllers/api/v1/accounts/lists_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/lists_controller_spec.rb @@ -21,5 +21,30 @@ get :index, params: { account_id: account.id } expect(response).to have_http_status(200) end + + context 'when request account is permanently deleted' do + before do + account.mark_deleted! + account.deletion_request.destroy + end + + it 'returns http not found' do + get :index, params: { account_id: account.id } + + expect(response).to have_http_status(404) + end + end + + context 'when request account is pending deletion' do + before do + account.mark_deleted! + end + + it 'returns http not found' do + get :index, params: { account_id: account.id } + + expect(response).to have_http_status(404) + end + end end end diff --git a/spec/controllers/api/v1/accounts/statuses_controller_spec.rb b/spec/controllers/api/v1/accounts/statuses_controller_spec.rb index 0e4fa930177c07..a44fda5b65ba85 100644 --- a/spec/controllers/api/v1/accounts/statuses_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/statuses_controller_spec.rb @@ -95,5 +95,34 @@ end end end + + context 'when request account is permanently deleted' do + let(:account) { Fabricate(:account) } + + before do + account.mark_deleted! + account.deletion_request.destroy + end + + it 'returns http not found' do + get :index, params: { account_id: account.id, limit: 2 } + + expect(response).to have_http_status(404) + end + end + + context 'when request account is pending deletion' do + let(:account) { Fabricate(:account) } + + before do + account.mark_deleted! + end + + it 'returns http not found' do + get :index, params: { account_id: account.id, limit: 2 } + + expect(response).to have_http_status(404) + end + end end end diff --git a/spec/requests/api/v1/accounts_spec.rb b/spec/requests/api/v1/accounts_spec.rb index e543c4136049dc..26da7b1590f3c3 100644 --- a/spec/requests/api/v1/accounts_spec.rb +++ b/spec/requests/api/v1/accounts_spec.rb @@ -29,6 +29,31 @@ end end + context 'when requesting a permanently deleted account' do + let(:other_account) { Fabricate(:account, deleted: true) } + + before do + get "/api/v1/accounts/#{other_account.id}" + end + + it 'returns http not found' do + expect(response).to have_http_status(404) + end + end + + context 'when requesting an account pending deletion' do + let(:other_account) { Fabricate(:account) } + + before do + other_account.mark_deleted! + get "/api/v1/accounts/#{other_account.id}" + end + + it 'returns http not found' do + expect(response).to have_http_status(404) + end + end + context 'when logged in' do subject do get "/api/v1/accounts/#{account.id}", headers: headers