2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do
|
2020-11-24 15:15:51 +05:30
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
it { is_expected.to have_graphql_field(:recorded_at) }
|
|
|
|
it { is_expected.to have_graphql_field(:identifier) }
|
|
|
|
it { is_expected.to have_graphql_field(:count) }
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
describe 'authorization' do
|
2021-04-17 20:07:23 +05:30
|
|
|
let_it_be(:measurement) { create(:usage_trends_measurement, :project_count) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
<<~GRAPHQL
|
2021-04-17 20:07:23 +05:30
|
|
|
query usageTrendsMeasurements($identifier: MeasurementIdentifier!) {
|
|
|
|
usageTrendsMeasurements(identifier: $identifier) {
|
2021-03-08 18:12:59 +05:30
|
|
|
nodes {
|
|
|
|
count
|
|
|
|
identifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
GitlabSchema.execute(
|
|
|
|
query,
|
|
|
|
variables: { identifier: 'PROJECTS' },
|
|
|
|
context: { current_user: user }
|
|
|
|
).to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is not admin' do
|
|
|
|
it 'returns no data' do
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(subject.dig('data', 'usageTrendsMeasurements')).to be_nil
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is an admin' do
|
|
|
|
let(:user) { create(:user, :admin) }
|
|
|
|
|
|
|
|
before do
|
2021-04-29 21:17:54 +05:30
|
|
|
stub_application_setting(admin_mode: false)
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns data' do
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|