debian-mirror-gitlab/spec/controllers/projects/service_ping_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

126 lines
3.6 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-09-30 23:02:18 +05:30
RSpec.describe Projects::ServicePingController do
2019-12-26 22:10:19 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
2020-05-24 23:13:21 +05:30
before do
sign_in(user) if user
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
shared_examples 'counter is not increased' do
context 'when the user is not authenticated' do
let(:user) { nil }
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
it 'returns 302' do
subject
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
expect(response).to have_gitlab_http_status(:found)
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
context 'when the user does not have access to the project' do
it 'returns 404' do
subject
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-12-26 22:10:19 +05:30
end
2020-05-24 23:13:21 +05:30
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
shared_examples 'counter is increased' do |counter|
context 'when the authenticated user has access to the project' do
2022-04-04 11:22:00 +05:30
let(:user) { project.first_owner }
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
it 'increments the usage counter' do
expect do
subject
end.to change { Gitlab::UsageDataCounters::WebIdeCounter.total_count(counter) }.by(1)
2019-12-26 22:10:19 +05:30
end
2020-05-24 23:13:21 +05:30
end
end
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
describe 'POST #web_ide_clientside_preview' do
subject { post :web_ide_clientside_preview, params: { namespace_id: project.namespace, project_id: project } }
2019-12-26 22:10:19 +05:30
2020-05-24 23:13:21 +05:30
context 'when web ide clientside preview is enabled' do
before do
stub_application_setting(web_ide_clientside_preview_enabled: true)
2019-12-26 22:10:19 +05:30
end
2020-05-24 23:13:21 +05:30
it_behaves_like 'counter is not increased'
it_behaves_like 'counter is increased', 'WEB_IDE_PREVIEWS_COUNT'
2019-12-26 22:10:19 +05:30
end
2022-04-04 11:22:00 +05:30
context 'when web ide clientside preview is not enabled' do
let(:user) { project.first_owner }
before do
stub_application_setting(web_ide_clientside_preview_enabled: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe 'POST #web_ide_clientside_preview_success' do
subject { post :web_ide_clientside_preview_success, params: { namespace_id: project.namespace, project_id: project } }
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_SUCCESS_COUNT'
2022-07-16 23:28:13 +05:30
2022-08-13 15:12:31 +05:30
context 'when the user has access to the project', :snowplow do
2022-07-16 23:28:13 +05:30
let(:user) { project.owner }
it 'increases the live preview view counter' do
2022-08-13 15:12:31 +05:30
expect(Gitlab::UsageDataCounters::EditorUniqueCounter).to receive(:track_live_preview_edit_action).with(author: user, project: project)
2022-07-16 23:28:13 +05:30
subject
expect(response).to have_gitlab_http_status(:ok)
end
2022-08-13 15:12:31 +05:30
it_behaves_like 'Snowplow event tracking' do
let(:project) { create(:project) }
let(:category) { 'ide_edit' }
let(:action) { 'g_edit_by_live_preview' }
let(:namespace) { project.namespace }
let(:feature_flag_name) { :route_hll_to_snowplow_phase2 }
end
2022-07-16 23:28:13 +05:30
end
2022-04-04 11:22:00 +05:30
end
2019-12-26 22:10:19 +05:30
context 'when web ide clientside preview is not enabled' do
let(:user) { project.owner }
before do
stub_application_setting(web_ide_clientside_preview_enabled: false)
end
it 'returns 404' do
subject
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-12-26 22:10:19 +05:30
end
end
end
2020-05-24 23:13:21 +05:30
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
2019-12-26 22:10:19 +05:30
end