summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/ci/groups_spec.rb
blob: 9e81358a152f038fc5584dcdf3f20335da9eec77 (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'Query.project.pipeline.stages.groups' do
  include GraphqlHelpers

  let(:project) { create(:project, :repository, :public) }
  let(:user) { create(:user) }
  let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
  let(:group_graphql_data) { graphql_data.dig('project', 'pipeline', 'stages', 'nodes', 0, 'groups', 'nodes') }

  let(:params) { {} }

  let(:fields) do
    <<~QUERY
      nodes {
        #{all_graphql_fields_for('CiGroup')}
      }
    QUERY
  end

  let(:query) do
    %(
      query {
        project(fullPath: "#{project.full_path}") {
          pipeline(iid: "#{pipeline.iid}") {
            stages {
              nodes {
                groups {
                  #{fields}
                }
              }
            }
          }
        }
      }
    )
  end

  before do
    create(:commit_status, pipeline: pipeline, name: 'rspec 0 2')
    create(:commit_status, pipeline: pipeline, name: 'rspec 0 1')
    create(:commit_status, pipeline: pipeline, name: 'spinach 0 1')
    post_graphql(query, current_user: user)
  end

  it_behaves_like 'a working graphql query'

  it 'returns a array of jobs belonging to a pipeline' do
    expect(group_graphql_data.map { |g| g.slice('name', 'size') }).to eq([
      { 'name' => 'rspec', 'size' => 2 },
      { 'name' => 'spinach', 'size' => 1 }
    ])
  end
end