summaryrefslogtreecommitdiff
path: root/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb
blob: 20a0cb842a4b0f45960af3a414cfe298fef19f52 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Resolvers::CommitPipelinesResolver do
  include GraphqlHelpers

  let_it_be(:project) { create(:project) }
  let(:commit) { create(:commit, project: project) }
  let_it_be(:current_user) { create(:user) }

  let!(:pipeline) do
    create(
      :ci_pipeline,
      project: project,
      sha: commit.id,
      ref: 'master',
      status: 'success'
    )
  end
  let!(:pipeline2) do
    create(
      :ci_pipeline,
      project: project,
      sha: commit.id,
      ref: 'master',
      status: 'failed'
    )
  end
  let!(:pipeline3) do
    create(
      :ci_pipeline,
      project: project,
      sha: commit.id,
      ref: 'my_branch',
      status: 'failed'
    )
  end

  before do
    commit.project.add_developer(current_user)
  end

  def resolve_pipelines
    resolve(described_class, obj: commit, ctx: { current_user: current_user }, args: { ref: 'master' })
  end

  it 'resolves pipelines for commit and ref' do
    pipelines = resolve_pipelines

    expect(pipelines).to eq([pipeline2, pipeline])
  end
end