File: create_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (66 lines) | stat: -rw-r--r-- 2,002 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'PipelineTriggerCreate', feature_category: :continuous_integration do
  include GraphqlHelpers

  let_it_be(:current_user) { create(:user) }
  let_it_be_with_reload(:project) { create(:project) }

  let(:mutation) { graphql_mutation(:pipeline_trigger_create, params) }
  let(:project_path) { project.full_path }
  let(:description) { 'Ye old pipeline trigger token' }

  let(:params) do
    {
      project_path: project_path,
      description: description
    }
  end

  subject { post_graphql_mutation(mutation, current_user: current_user) }

  context 'when unauthorized' do
    it_behaves_like 'a mutation on an unauthorized resource'
  end

  context 'when authorized' do
    before_all do
      project.add_owner(current_user)
    end

    context 'when the params are invalid' do
      let(:description) { nil }

      it 'does not create a pipeline trigger token and returns an error' do
        expect { subject }.not_to change { project.triggers.count }
        expect(response).to have_gitlab_http_status(:success)
        expect(graphql_errors.to_s).to include('provided invalid value for description (Expected value to not be null)')
      end
    end

    context 'when the params are valid' do
      it 'creates a pipeline trigger token' do
        expect { subject }.to change { project.triggers.count }.by(1)
        expect(graphql_errors.to_s).to eql("")
      end

      it 'returns the new pipeline trigger token' do
        subject

        expect(graphql_data_at(:pipeline_trigger_create, :pipeline_trigger)).to match a_hash_including(
          'owner' => a_hash_including(
            'id' => current_user.to_global_id.to_s,
            'username' => current_user.username,
            'name' => current_user.name
          ),
          'description' => description,
          "canAccessProject" => true,
          "hasTokenExposed" => true,
          "lastUsed" => nil
        )
      end
    end
  end
end