Welcome to mirror list, hosted at ThFree Co, Russian Federation.

measurement_type_spec.rb « usage_trends « analytics « admin « types « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d1c2b4044c14417f096d9567054ee27440217a8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe GitlabSchema.types['UsageTrendsMeasurement'] do
  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) }

  describe 'authorization' do
    let_it_be(:measurement) { create(:usage_trends_measurement, :project_count) }

    let(:user) { create(:user) }

    let(:query) do
      <<~GRAPHQL
        query usageTrendsMeasurements($identifier: MeasurementIdentifier!) {
          usageTrendsMeasurements(identifier: $identifier) {
            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
        expect(subject.dig('data', 'usageTrendsMeasurements')).to be_nil
      end
    end

    context 'when user is an admin' do
      let(:user) { create(:user, :admin) }

      before do
        stub_application_setting(admin_mode: false)
      end

      it 'returns data' do
        expect(subject.dig('data', 'usageTrendsMeasurements', 'nodes')).not_to be_empty
      end
    end
  end
end