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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Admin views Subscription', :js do
let_it_be(:admin) { create(:admin) }
before do
stub_feature_flags(bootstrap_confirmation_modals: false)
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
end
shared_examples 'an "Export license usage file" button' do
it 'displays the Export License Usage File button' do
expect(page).to have_link('Export license usage file', href: admin_license_usage_export_path(format: :csv))
end
end
shared_examples 'license removal' do
context 'when removing a license file' do
before do
accept_alert do
click_on 'Remove license'
end
end
it 'shows a message saying the license was correctly removed' do
page.within(find('#content-body', match: :first)) do
expect(page).to have_content('The license was removed.')
end
end
end
end
shared_examples 'no active license' do
it 'displays a message signaling there is not active subscription' do
page.within(find('#content-body', match: :first)) do
expect(page).to have_content('You do not have an active subscription')
end
end
end
context 'with a cloud license' do
let!(:license) { create_current_license(cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN) }
context 'with a cloud license only' do
before do
visit(admin_subscription_path)
end
it 'displays the subscription details' do
page.within(find('#content-body', match: :first)) do
expect(page).to have_content('Subscription details')
expect(all("[data-testid='details-label']")[1]).to have_content('Plan:')
expect(all("[data-testid='details-content']")[1]).to have_content('Ultimate')
end
end
it 'succeeds to sync the subscription' do
page.within(find('#content-body', match: :first)) do
click_button('Sync subscription details')
expect(page).to have_content('Your subscription details will sync shortly.')
end
end
it 'fails to sync the subscription' do
create_current_license(cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN, expires_at: nil)
page.within(find('#content-body', match: :first)) do
click_button('Sync subscription details')
expect(page).to have_content('You can no longer sync your subscription details with GitLab. Get help for the most common connectivity issues by troubleshooting the activation code')
end
end
it_behaves_like 'an "Export license usage file" button'
it_behaves_like 'license removal'
end
end
context 'with license file' do
let!(:license) { create_current_license(cloud_licensing_enabled: false, plan: License::ULTIMATE_PLAN) }
before do
visit(admin_subscription_path)
end
it_behaves_like 'an "Export license usage file" button'
it_behaves_like 'license removal'
context 'when activating another subscription' do
before do
page.within(find('[data-testid="subscription-details"]', match: :first)) do
click_button('Enter activation code')
end
end
it 'shows the activation modal' do
page.within(find('#subscription-activation-modal', match: :first)) do
expect(page).to have_content('Activate subscription')
end
end
it 'displays an error when the activation fails' do
stub_request(:post, EE::SUBSCRIPTIONS_GRAPHQL_URL).to_return(status: 422, body: '', headers: {})
page.within(find('#subscription-activation-modal', match: :first)) do
fill_activation_form
expect(page).to have_content('An error occurred while activating your subscription.')
end
end
it 'displays a connectivity error' do
stub_request(:post, EE::SUBSCRIPTIONS_GRAPHQL_URL)
.to_return(status: 500, body: '', headers: {})
page.within(find('#subscription-activation-modal', match: :first)) do
fill_activation_form
expect(page).to have_content('There is a connectivity issue.')
end
end
end
end
context 'with no active subscription' do
let_it_be(:license_to_be_created) { nil }
before do
License.current.destroy!
visit(admin_subscription_path)
end
it_behaves_like 'no active license'
it 'does not display the Export License Usage File button' do
expect(page).not_to have_link('Export license usage file', href: admin_license_usage_export_path(format: :csv))
end
context 'when activating a subscription fails' do
before do
stub_request(:post, EE::SUBSCRIPTIONS_GRAPHQL_URL)
.to_return(status: 200, body: {
"data": {
"cloudActivationActivate": {
"errors": ["invalid activation code"],
"license": license_to_be_created
},
"success": "true"
}
}.to_json, headers: { 'Content-Type' => 'application/json' })
page.within(find('#content-body', match: :first)) do
fill_activation_form
end
end
it 'shows an error message' do
expect(page).to have_content('An error occurred while activating your subscription.')
end
end
context 'when activating a future-dated subscription' do
let_it_be(:license_to_be_created) { build(:license, data: build(:gitlab_license, { starts_at: Date.current + 1.month, cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN }).export) }
before do
stub_request(:post, EE::SUBSCRIPTIONS_GRAPHQL_URL)
.to_return(status: 200, body: {
"data": {
"cloudActivationActivate": {
"licenseKey": license_to_be_created.data
}
}
}.to_json, headers: { 'Content-Type' => 'application/json' })
page.within(find('#content-body', match: :first)) do
fill_activation_form
end
end
it 'shows a successful future-dated activation message' do
expect(page).to have_content('Your future dated license was successfully added')
end
it_behaves_like 'no active license'
end
context 'when activating a new subscription' do
let_it_be(:license_to_be_created) { build(:license, data: build(:gitlab_license, { starts_at: Date.current, cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN }).export) }
before do
stub_request(:post, EE::SUBSCRIPTIONS_GRAPHQL_URL)
.to_return(status: 200, body: {
"data": {
"cloudActivationActivate": {
"licenseKey": license_to_be_created.data
}
}
}.to_json, headers: { 'Content-Type' => 'application/json' })
page.within(find('#content-body', match: :first)) do
fill_activation_form
end
end
it 'shows a successful activation message' do
expect(page).to have_content('Your subscription was successfully activated.')
end
it 'shows the subscription details' do
expect(page).to have_content('Subscription details')
end
it 'shows the appropriate license type' do
page.within(find('[data-testid="subscription-cell-type"]', match: :first)) do
expect(page).to have_content('Cloud license')
end
end
end
context 'when uploading a license file' do
it 'does not show a link to activate a license file' do
page.within(find('#content-body', match: :first)) do
expect(page).not_to have_link('Activate a license', href: new_admin_license_path)
end
end
end
end
include_examples 'manual renewal banner', path_to_visit: :admin_subscription_path
include_examples 'manual quarterly co-term banner', path_to_visit: :admin_subscription_path
private
def fill_activation_form
fill_in 'activationCode', with: '00112233aaaassssddddffff'
check 'subscription-form-terms-check'
click_button 'Activate'
end
end