0
0
Fork 0

Clean up of RSpec/LetSetup within api/ (#28448)

This commit is contained in:
Matt Jankowski 2023-12-21 05:10:18 -05:00 committed by GitHub
parent 5976d3702f
commit cd64a5b2ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 25 deletions

View file

@ -34,28 +34,56 @@ RSpec.describe Api::V2::Admin::AccountsController do
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', ''
[
[{ status: 'active', origin: 'local', permissions: 'staff' }, [:admin_account]],
[{ by_domain: 'example.org', origin: 'remote' }, [:remote_account]],
[{ status: 'suspended' }, [:suspended_remote, :suspended_account]],
[{ status: 'disabled' }, [:disabled_account]],
[{ status: 'pending' }, [:pending_account]],
].each do |params, expected_results|
context "when called with #{params.inspect}" do
let(:params) { params }
context 'when called with status active and origin local and permissions staff' do
let(:params) { { status: 'active', origin: 'local', permissions: 'staff' } }
it "returns the correct accounts (#{expected_results.inspect})" do
expect(response).to have_http_status(200)
expect(body_json_ids).to eq(expected_results.map { |symbol| send(symbol).id })
end
def body_json_ids
body_as_json.map { |a| a[:id].to_i }
end
it 'returns the correct accounts' do
expect(response).to have_http_status(200)
expect(body_json_ids).to eq([admin_account.id])
end
end
context 'when called with by_domain value and origin remote' do
let(:params) { { by_domain: 'example.org', origin: 'remote' } }
it 'returns the correct accounts' do
expect(response).to have_http_status(200)
expect(body_json_ids).to include(remote_account.id)
expect(body_json_ids).to_not include(other_remote_account.id)
end
end
context 'when called with status suspended' do
let(:params) { { status: 'suspended' } }
it 'returns the correct accounts' do
expect(response).to have_http_status(200)
expect(body_json_ids).to include(suspended_remote.id, suspended_account.id)
end
end
context 'when called with status disabled' do
let(:params) { { status: 'disabled' } }
it 'returns the correct accounts' do
expect(response).to have_http_status(200)
expect(body_json_ids).to include(disabled_account.id)
end
end
context 'when called with status pending' do
let(:params) { { status: 'pending' } }
it 'returns the correct accounts' do
expect(response).to have_http_status(200)
expect(body_json_ids).to include(pending_account.id)
end
end
def body_json_ids
body_as_json.map { |a| a[:id].to_i }
end
context 'with limit param' do
let(:params) { { limit: 1 } }