blob: b2dd94f31bbc20a6e01e4f52254aba391318c506 (
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
76
77
78
79
80
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Labels::Create do
let_it_be(:user) { create(:user) }
let(:attributes) do
{
title: 'new title',
description: 'A new label'
}
end
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
let(:mutated_label) { subject[:label] }
shared_examples 'create labels mutation' do
describe '#resolve' do
subject { mutation.resolve(attributes.merge(extra_params)) }
context 'when the user does not have permission to create a label' do
before do
parent.add_guest(user)
end
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
context 'when the user can create a label' do
before do
parent.add_developer(user)
end
it 'creates label with correct values' do
expect(mutated_label).to have_attributes(attributes)
end
end
end
end
specify { expect(described_class).to require_graphql_authorizations(:admin_label) }
context 'when creating a project label' do
let_it_be(:parent) { create(:project) }
let(:extra_params) { { project_path: parent.full_path } }
it_behaves_like 'create labels mutation'
end
context 'when creating a group label' do
let_it_be(:parent) { create(:group) }
let(:extra_params) { { group_path: parent.full_path } }
it_behaves_like 'create labels mutation'
end
describe '#ready?' do
subject { mutation.ready?(**attributes.merge(extra_params)) }
context 'when passing both project_path and group_path' do
let(:extra_params) { { project_path: 'foo', group_path: 'bar' } }
it 'raises an argument error' do
expect { subject }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Exactly one of/)
end
end
context 'when passing only project_path or group_path' do
let(:extra_params) { { project_path: 'foo' } }
it 'does not raise an error' do
expect { subject }.not_to raise_error
end
end
end
end
|