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

destroy_spec.rb « job_artifact « 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: a5ec9ea343dbe371412641a422dbf676710b465e (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'ArtifactDestroy' do
  include GraphqlHelpers

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

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

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

    expect(graphql_errors).not_to be_empty
  end

  context 'when the user is allowed to destroy the artifact' do
    before do
      artifact.job.project.add_maintainer(user)
    end

    it 'destroys the artifact' do
      post_graphql_mutation(mutation, current_user: user)

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

    it 'returns error if destory fails' do
      allow_next_found_instance_of(Ci::JobArtifact) do |instance|
        allow(instance).to receive(:destroy).and_return(false)
        allow(instance).to receive_message_chain(:errors, :full_messages).and_return(['cannot be removed'])
      end

      post_graphql_mutation(mutation, current_user: user)

      expect(graphql_data_at(:artifact_destroy, :errors)).to contain_exactly('cannot be removed')
    end
  end
end