feat: Add route to list accounts that belongs to a platform_app (#12140)
This PR creates a new route to list all accounts that a platform_app has access to. Fixes: #12109
This commit is contained in:
@@ -78,6 +78,42 @@ RSpec.describe 'Platform Accounts API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /platform/api/v1/accounts' do
|
||||
context 'when it is an unauthenticated platform app' do
|
||||
it 'returns unauthorized' do
|
||||
get '/platform/api/v1/accounts'
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an invalid platform app token' do
|
||||
it 'returns unauthorized' do
|
||||
get '/platform/api/v1/accounts', headers: { api_access_token: 'invalid' }, as: :json
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated platform app' do
|
||||
let(:platform_app) { create(:platform_app) }
|
||||
let!(:account1) { create(:account, name: 'Account A') }
|
||||
let!(:account2) { create(:account, name: 'Account B') }
|
||||
|
||||
before do
|
||||
create(:platform_app_permissible, platform_app: platform_app, permissible: account1)
|
||||
create(:platform_app_permissible, platform_app: platform_app, permissible: account2)
|
||||
end
|
||||
|
||||
it 'returns all permissible accounts' do
|
||||
get '/platform/api/v1/accounts', headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response.size).to eq(2)
|
||||
expect(json_response.map { |acc| acc['name'] }).to include('Account A', 'Account B')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /platform/api/v1/accounts/{account_id}' do
|
||||
context 'when it is an unauthenticated platform app' do
|
||||
it 'returns unauthorized' do
|
||||
|
||||
Reference in New Issue
Block a user