summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/ci/config_spec.rb
blob: b682470e0a1224b172766680dcc9007b8e7b8364 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Query.ciConfig' do
  include GraphqlHelpers

  subject(:post_graphql_query) { post_graphql(query, current_user: user) }

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

  let_it_be(:content) do
    File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
  end

  let(:query) do
    %(
      query {
        ciConfig(content: "#{content}") {
          status
          errors
          stages {
            name
            groups {
              name
              size
              jobs {
                name
                groupName
                stage
                needs {
                  name
                }
              }
            }
          }
        }
      }
    )
  end

  before do
    post_graphql_query
  end

  it_behaves_like 'a working graphql query'

  it 'returns the correct structure' do
    expect(graphql_data['ciConfig']).to eq(
      "status" => "VALID",
      "errors" => [],
      "stages" =>
      [
        {
          "name" => "build",
          "groups" =>
          [
            {
              "name" => "rspec",
              "size" => 2,
              "jobs" =>
              [
                { "name" => "rspec 0 1", "groupName" => "rspec", "stage" => "build", "needs" => [] },
                { "name" => "rspec 0 2", "groupName" => "rspec", "stage" => "build", "needs" => [] }
              ]
            },
            {
              "name" => "spinach", "size" => 1, "jobs" =>
              [
                { "name" => "spinach", "groupName" => "spinach", "stage" => "build", "needs" => [] }
              ]
            }
          ]
        },
        {
          "name" => "test",
          "groups" =>
          [
            {
              "name" => "docker",
              "size" => 1,
              "jobs" => [
                { "name" => "docker", "groupName" => "docker", "stage" => "test", "needs" => [{ "name" => "spinach" }, { "name" => "rspec 0 1" }] }
              ]
            }
          ]
        }
      ]
    )
  end
end