diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/requests/api/usage_data_queries_spec.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/requests/api/usage_data_queries_spec.rb')
-rw-r--r-- | spec/requests/api/usage_data_queries_spec.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/requests/api/usage_data_queries_spec.rb b/spec/requests/api/usage_data_queries_spec.rb new file mode 100644 index 00000000000..0ba4a37bc9b --- /dev/null +++ b/spec/requests/api/usage_data_queries_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::UsageDataQueries do + include UsageDataHelpers + + let_it_be(:admin) { create(:user, admin: true) } + let_it_be(:user) { create(:user) } + + before do + stub_usage_data_connections + end + + describe 'GET /usage_data/usage_data_queries' do + let(:endpoint) { '/usage_data/queries' } + + context 'with authentication' do + before do + stub_feature_flags(usage_data_queries_api: true) + end + + it 'returns queries if user is admin' do + get api(endpoint, admin) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['active_user_count']).to start_with('SELECT COUNT("users"."id") FROM "users"') + end + + it 'returns forbidden if user is not admin' do + get api(endpoint, user) + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'without authentication' do + before do + stub_feature_flags(usage_data_queries_api: true) + end + + it 'returns unauthorized' do + get api(endpoint) + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + + context 'when feature_flag is disabled' do + before do + stub_feature_flags(usage_data_queries_api: false) + end + + it 'returns not_found for admin' do + get api(endpoint, admin) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it 'returns forbidden for non-admin' do + get api(endpoint, user) + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + end +end |