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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::HookData::ProjectBuilder do
let_it_be(:user) { create(:user, name: 'John', email: 'john@example.com') }
let_it_be(:user2) { create(:user, name: 'Peter') }
let_it_be(:user3_non_owner) { create(:user, name: 'Not_Owner') }
describe '#build' do
let(:data) { described_class.new(project).build(event) }
let(:event_name) { data[:event_name] }
let(:attributes) do
[
:event_name, :created_at, :updated_at, :name, :path, :path_with_namespace, :project_id,
:owners, :owner_name, :owner_email, :project_visibility
]
end
context 'data' do
shared_examples_for 'includes the required attributes' do
it 'includes the required attributes' do
expect(data).to include(*attributes)
expect(data[:created_at]).to eq(project.created_at.xmlschema)
expect(data[:updated_at]).to eq(project.updated_at.xmlschema)
expect(data[:name]).to eq(project.name)
expect(data[:path]).to eq(project.path)
expect(data[:path_with_namespace]).to eq(project.full_path)
expect(data[:project_id]).to eq(project.id)
expect(data[:owner_name]).to eq(owner_name)
expect(data[:owner_email]).to eq(owner_email)
expect(data[:owners]).to match_array(owners_data)
expect(data[:project_visibility]).to eq('internal')
end
end
shared_examples_for 'does not include `old_path_with_namespace` attribute' do
it 'does not include `old_path_with_namespace` attribute' do
expect(data).not_to include(:old_path_with_namespace)
end
end
shared_examples_for 'includes `old_path_with_namespace` attribute' do
it 'includes `old_path_with_namespace` attribute' do
allow(project).to receive(:old_path_with_namespace).and_return('old-path-with-namespace')
expect(data[:old_path_with_namespace]).to eq('old-path-with-namespace')
end
end
context 'the project is created in a personal namespace' do
let(:owner_name) { user.name }
let(:owner_email) { _('[REDACTED]') }
let(:owners_data) { [{ name: 'John', email: _('[REDACTED]') }, { name: 'Peter', email: _('[REDACTED]') }] }
let_it_be(:namespace) { create(:namespace, owner: user) }
let_it_be(:project) { create(:project, :internal, name: 'personal project', namespace: namespace) }
before_all do
project.add_owner(user2)
project.add_maintainer(user3_non_owner)
end
context 'on create' do
let(:event) { :create }
it { expect(event_name).to eq('project_create') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'does not include `old_path_with_namespace` attribute'
end
context 'on destroy' do
let(:event) { :destroy }
it { expect(event_name).to eq('project_destroy') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'does not include `old_path_with_namespace` attribute'
end
context 'on rename' do
let(:event) { :rename }
it { expect(event_name).to eq('project_rename') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'includes `old_path_with_namespace` attribute'
end
context 'on transfer' do
let(:event) { :transfer }
it { expect(event_name).to eq('project_transfer') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'includes `old_path_with_namespace` attribute'
end
end
context 'the project is created in a group' do
let(:owner_name) { group.name }
let(:owner_email) { "" }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :internal, name: 'group project', namespace: group) }
let(:owners_data) { [{ name: 'John', email: _('[REDACTED]') }, { email: "[REDACTED]", name: "Peter" }] }
before_all do
group.add_owner(user)
group.add_owner(user2)
group.add_maintainer(user3_non_owner)
end
# Repeat the tests in the previous context
context 'on create' do
let(:event) { :create }
it { expect(event_name).to eq('project_create') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'does not include `old_path_with_namespace` attribute'
end
context 'on destroy' do
let(:event) { :destroy }
it { expect(event_name).to eq('project_destroy') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'does not include `old_path_with_namespace` attribute'
end
context 'on rename' do
let(:event) { :rename }
it { expect(event_name).to eq('project_rename') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'includes `old_path_with_namespace` attribute'
end
context 'on transfer' do
let(:event) { :transfer }
it { expect(event_name).to eq('project_transfer') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'includes `old_path_with_namespace` attribute'
end
end
end
end
end
|