blob: 1af12d51e1e536b6fe6049a03f46bc013a4961dd (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineTriggerCreate', feature_category: :continuous_integration do
include GraphqlHelpers
let_it_be(: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: user) }
context 'when unauthorized' do
it 'returns an error' do
subject
expect(graphql_errors).not_to be_empty
expect(graphql_errors[0]['message'])
.to eq(
"The resource that you are attempting to access does not exist " \
"or you don't have permission to perform this action"
)
end
end
context 'when authorized' do
before_all do
project.add_owner(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' => user.to_global_id.to_s,
'username' => user.username,
'name' => user.name
),
'description' => description,
"canAccessProject" => true,
"hasTokenExposed" => true,
"lastUsed" => nil
)
end
end
end
end
|