summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/usage_ping_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/projects/usage_ping_controller_spec.rb')
-rw-r--r--spec/controllers/projects/usage_ping_controller_spec.rb68
1 files changed, 41 insertions, 27 deletions
diff --git a/spec/controllers/projects/usage_ping_controller_spec.rb b/spec/controllers/projects/usage_ping_controller_spec.rb
index 284db93d7a8..a68967c228f 100644
--- a/spec/controllers/projects/usage_ping_controller_spec.rb
+++ b/spec/controllers/projects/usage_ping_controller_spec.rb
@@ -6,45 +6,52 @@ describe Projects::UsagePingController do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
- describe 'POST #web_ide_clientside_preview' do
- subject { post :web_ide_clientside_preview, params: { namespace_id: project.namespace, project_id: project } }
+ before do
+ sign_in(user) if user
+ end
- before do
- sign_in(user) if user
- end
+ shared_examples 'counter is not increased' do
+ context 'when the user is not authenticated' do
+ let(:user) { nil }
- context 'when web ide clientside preview is enabled' do
- before do
- stub_application_setting(web_ide_clientside_preview_enabled: true)
- end
+ it 'returns 302' do
+ subject
- context 'when the user is not authenticated' do
- let(:user) { nil }
+ expect(response).to have_gitlab_http_status(:found)
+ end
+ end
- it 'returns 302' do
- subject
+ context 'when the user does not have access to the project' do
+ it 'returns 404' do
+ subject
- expect(response).to have_gitlab_http_status(:found)
- end
+ expect(response).to have_gitlab_http_status(:not_found)
end
+ end
+ end
- context 'when the user does not have access to the project' do
- it 'returns 404' do
- subject
+ shared_examples 'counter is increased' do |counter|
+ context 'when the authenticated user has access to the project' do
+ let(:user) { project.owner }
- expect(response).to have_gitlab_http_status(:not_found)
- end
+ it 'increments the usage counter' do
+ expect do
+ subject
+ end.to change { Gitlab::UsageDataCounters::WebIdeCounter.total_count(counter) }.by(1)
end
+ end
+ end
- context 'when the user has access to the project' do
- let(:user) { project.owner }
+ describe 'POST #web_ide_clientside_preview' do
+ subject { post :web_ide_clientside_preview, params: { namespace_id: project.namespace, project_id: project } }
- it 'increments the counter' do
- expect do
- subject
- end.to change { Gitlab::UsageDataCounters::WebIdeCounter.total_previews_count }.by(1)
- end
+ context 'when web ide clientside preview is enabled' do
+ before do
+ stub_application_setting(web_ide_clientside_preview_enabled: true)
end
+
+ it_behaves_like 'counter is not increased'
+ it_behaves_like 'counter is increased', 'WEB_IDE_PREVIEWS_COUNT'
end
context 'when web ide clientside preview is not enabled' do
@@ -61,4 +68,11 @@ describe Projects::UsagePingController do
end
end
end
+
+ describe 'POST #web_ide_pipelines_count' do
+ subject { post :web_ide_pipelines_count, params: { namespace_id: project.namespace, project_id: project } }
+
+ it_behaves_like 'counter is not increased'
+ it_behaves_like 'counter is increased', 'WEB_IDE_PIPELINES_COUNT'
+ end
end