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

runner_web_url_edge_spec.rb « ci « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 76e2dda4ce2c61db768c8655aa018e69908231e7 (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
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'RunnerWebUrlEdge', feature_category: :runner_fleet do
  include GraphqlHelpers

  describe 'inside a Query.group' do
    let_it_be(:group) { create(:group) }
    let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) }

    let(:edges_graphql_data) { graphql_data.dig('group', 'runners', 'edges') }

    let(:query) do
      <<~GQL
        query($path: ID!) {
          group(fullPath: $path) {
            runners {
              edges {
                editUrl
                webUrl
              }
            }
          }
        }
      GQL
    end

    subject(:request) do
      post_graphql(query, current_user: user, variables: { path: group.full_path })
    end

    context 'with an authorized user' do
      let(:user) { create_default(:user, :admin) }

      it_behaves_like 'a working graphql query' do
        before do
          request
        end
      end

      it 'returns correct URLs' do
        request

        expect(edges_graphql_data).to match_array [
          {
            'editUrl' => Gitlab::Routing.url_helpers.edit_group_runner_url(group, group_runner),
            'webUrl' => Gitlab::Routing.url_helpers.group_runner_url(group, group_runner)
          }
        ]
      end
    end

    context 'with an unauthorized user' do
      let(:user) { create(:user) }

      it 'returns nil runners and an error' do
        request

        expect(graphql_data.dig('group', 'runners')).to be_nil
        expect(graphql_errors).to contain_exactly(a_hash_including(
          'message' => a_string_including("you don't have permission to perform this action"),
          'path' => %w[group runners]
        ))
      end
    end
  end
end