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

pipeline_destroy_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: 7abd5ca8772b26e17caba59e0fcc553b6ea05397 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'PipelineDestroy' do
  include GraphqlHelpers

  let_it_be(:project) { create(:project) }
  let_it_be(:user) { project.first_owner }
  let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project, user: user) }

  let(:mutation) do
    variables = {
      id: pipeline.to_global_id.to_s
    }
    graphql_mutation(:pipeline_destroy, variables, 'errors')
  end

  it 'returns an error if the user is not allowed to destroy the pipeline' do
    post_graphql_mutation(mutation, current_user: create(:user))

    expect(graphql_errors).not_to be_empty
  end

  it 'destroys a pipeline' do
    post_graphql_mutation(mutation, current_user: user)

    expect(response).to have_gitlab_http_status(:success)
    expect { pipeline.reload }.to raise_error(ActiveRecord::RecordNotFound)
  end

  context 'when project is undergoing stats refresh' do
    before do
      create(:project_build_artifacts_size_refresh, :pending, project: pipeline.project)
    end

    it 'returns an error and does not destroy the pipeline' do
      expect(Gitlab::ProjectStatsRefreshConflictsLogger)
        .to receive(:warn_request_rejected_during_stats_refresh)
        .with(pipeline.project.id)

      post_graphql_mutation(mutation, current_user: user)

      expect(graphql_mutation_response(:pipeline_destroy)['errors']).not_to be_empty
      expect(pipeline.reload).to be_persisted
    end
  end
end