From 30ee4aaff44784fb901e0a934e7416de30a4edf0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 21 Nov 2023 09:25:07 -0500 Subject: [PATCH] Convert measurement `api/v1/admin/*` controller specs to request specs (#28005) --- .../v1/admin/dimensions_controller_spec.rb | 23 ------------ .../api/v1/admin/measures_controller_spec.rb | 23 ------------ .../api/v1/admin/retention_controller_spec.rb | 23 ------------ spec/requests/api/v1/admin/dimensions_spec.rb | 35 +++++++++++++++++++ spec/requests/api/v1/admin/measures_spec.rb | 35 +++++++++++++++++++ spec/requests/api/v1/admin/retention_spec.rb | 35 +++++++++++++++++++ 6 files changed, 105 insertions(+), 69 deletions(-) delete mode 100644 spec/controllers/api/v1/admin/dimensions_controller_spec.rb delete mode 100644 spec/controllers/api/v1/admin/measures_controller_spec.rb delete mode 100644 spec/controllers/api/v1/admin/retention_controller_spec.rb create mode 100644 spec/requests/api/v1/admin/dimensions_spec.rb create mode 100644 spec/requests/api/v1/admin/measures_spec.rb create mode 100644 spec/requests/api/v1/admin/retention_spec.rb diff --git a/spec/controllers/api/v1/admin/dimensions_controller_spec.rb b/spec/controllers/api/v1/admin/dimensions_controller_spec.rb deleted file mode 100644 index ea18efe383..0000000000 --- a/spec/controllers/api/v1/admin/dimensions_controller_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Api::V1::Admin::DimensionsController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'admin:read') } - let(:account) { Fabricate(:account) } - - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'POST #create' do - it 'returns http success' do - post :create, params: { account_id: account.id, limit: 2 } - - expect(response).to have_http_status(200) - end - end -end diff --git a/spec/controllers/api/v1/admin/measures_controller_spec.rb b/spec/controllers/api/v1/admin/measures_controller_spec.rb deleted file mode 100644 index 03727a6329..0000000000 --- a/spec/controllers/api/v1/admin/measures_controller_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Api::V1::Admin::MeasuresController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'admin:read') } - let(:account) { Fabricate(:account) } - - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'POST #create' do - it 'returns http success' do - post :create, params: { account_id: account.id, limit: 2 } - - expect(response).to have_http_status(200) - end - end -end diff --git a/spec/controllers/api/v1/admin/retention_controller_spec.rb b/spec/controllers/api/v1/admin/retention_controller_spec.rb deleted file mode 100644 index 2381dbcb48..0000000000 --- a/spec/controllers/api/v1/admin/retention_controller_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Api::V1::Admin::RetentionController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'admin:read') } - let(:account) { Fabricate(:account) } - - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'POST #create' do - it 'returns http success' do - post :create, params: { account_id: account.id, limit: 2 } - - expect(response).to have_http_status(200) - end - end -end diff --git a/spec/requests/api/v1/admin/dimensions_spec.rb b/spec/requests/api/v1/admin/dimensions_spec.rb new file mode 100644 index 0000000000..87534a74b8 --- /dev/null +++ b/spec/requests/api/v1/admin/dimensions_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin Dimensions' do + 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/dimensions' do + context 'when not authorized' do + it 'returns http forbidden' do + post '/api/v1/admin/dimensions', params: { account_id: account.id, limit: 2 } + + expect(response) + .to have_http_status(403) + end + end + + context 'with correct scope' do + let(:scopes) { 'admin:read' } + + it 'returns http success and status json' do + post '/api/v1/admin/dimensions', params: { account_id: account.id, limit: 2 }, headers: headers + + expect(response) + .to have_http_status(200) + + expect(body_as_json) + .to be_an(Array) + end + end + end +end diff --git a/spec/requests/api/v1/admin/measures_spec.rb b/spec/requests/api/v1/admin/measures_spec.rb new file mode 100644 index 0000000000..15f2df84c6 --- /dev/null +++ b/spec/requests/api/v1/admin/measures_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin Measures' do + 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/measures' do + context 'when not authorized' do + it 'returns http forbidden' do + post '/api/v1/admin/measures', params: { account_id: account.id, limit: 2 } + + expect(response) + .to have_http_status(403) + end + end + + context 'with correct scope' do + let(:scopes) { 'admin:read' } + + it 'returns http success and status json' do + post '/api/v1/admin/measures', params: { account_id: account.id, limit: 2 }, headers: headers + + expect(response) + .to have_http_status(200) + + expect(body_as_json) + .to be_an(Array) + end + end + end +end diff --git a/spec/requests/api/v1/admin/retention_spec.rb b/spec/requests/api/v1/admin/retention_spec.rb new file mode 100644 index 0000000000..9178335ba5 --- /dev/null +++ b/spec/requests/api/v1/admin/retention_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin Retention' do + 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) + 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) + + expect(body_as_json) + .to be_an(Array) + end + end + end +end