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

job_cancel_spec.rb « ci « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ee0f0a9bccb30ae0bd4ac8b819ec0ccce44a88c3 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe "JobCancel" do
  include GraphqlHelpers

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
  let_it_be(:job) { create(:ci_build, pipeline: pipeline, name: 'build') }

  let(:mutation) do
    variables = {
      id: job.to_global_id.to_s
    }
    graphql_mutation(:job_cancel, variables,
                     <<-QL
                       errors
                       job {
                         id
                       }
                     QL
    )
  end

  let(:mutation_response) { graphql_mutation_response(:job_cancel) }

  it 'returns an error if the user is not allowed to cancel the job' do
    project.add_developer(user)
    post_graphql_mutation(mutation, current_user: user)

    expect(graphql_errors).not_to be_empty
  end

  it 'cancels a job' do
    job_id = ::Gitlab::GlobalId.build(job, id: job.id).to_s
    project.add_maintainer(user)
    post_graphql_mutation(mutation, current_user: user)

    expect(response).to have_gitlab_http_status(:success)
    expect(mutation_response['job']['id']).to eq(job_id)
    expect(job.reload.status).to eq('canceled')
  end
end