2023-11-21 23:25:07 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe 'Admin Retention' do
|
2023-11-21 23:25:07 +09:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
describe 'GET /api/v1/admin/retention' do
|
|
|
|
context 'when not authorized' do
|
|
|
|
it 'returns http forbidden' do
|
|
|
|
post '/api/v1/admin/retention', params: { account_id: account.id, limit: 2 }
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(403)
|
2024-09-20 22:13:04 +09:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-11-21 23:25:07 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with correct scope' do
|
|
|
|
let(:scopes) { 'admin:read' }
|
|
|
|
|
|
|
|
it 'returns http success and status json' do
|
|
|
|
post '/api/v1/admin/retention', params: { account_id: account.id, limit: 2 }, headers: headers
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
2024-09-20 22:13:04 +09:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-11-21 23:25:07 +09:00
|
|
|
|
2024-09-06 18:58:46 +09:00
|
|
|
expect(response.parsed_body)
|
2023-11-21 23:25:07 +09:00
|
|
|
.to be_an(Array)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|