2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_state do
|
2020-05-24 23:13:21 +05:30
|
|
|
shared_examples 'counter examples' do |event|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'increments counter and return the total count' do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class.public_send(:total_count, event)).to eq(0)
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
2.times { described_class.public_send(:"increment_#{event}_count") }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
redis_key = "web_ide_#{event}_count".upcase
|
|
|
|
expect(described_class.public_send(:total_count, redis_key)).to eq(2)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe 'commits counter' do
|
2020-05-24 23:13:21 +05:30
|
|
|
it_behaves_like 'counter examples', 'commits'
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'merge requests counter' do
|
2020-05-24 23:13:21 +05:30
|
|
|
it_behaves_like 'counter examples', 'merge_requests'
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'views counter' do
|
2020-05-24 23:13:21 +05:30
|
|
|
it_behaves_like 'counter examples', 'views'
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
describe 'terminals counter' do
|
|
|
|
it_behaves_like 'counter examples', 'terminals'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'pipelines counter' do
|
|
|
|
it_behaves_like 'counter examples', 'pipelines'
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe 'previews counter' do
|
|
|
|
let(:setting_enabled) { true }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(web_ide_clientside_preview_enabled: setting_enabled)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when web ide clientside preview is enabled' do
|
2020-05-24 23:13:21 +05:30
|
|
|
it_behaves_like 'counter examples', 'previews'
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when web ide clientside preview is not enabled' do
|
|
|
|
let(:setting_enabled) { false }
|
|
|
|
|
|
|
|
it 'does not increment the counter' do
|
2020-05-24 23:13:21 +05:30
|
|
|
redis_key = 'WEB_IDE_PREVIEWS_COUNT'
|
|
|
|
expect(described_class.total_count(redis_key)).to eq(0)
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
2.times { described_class.increment_previews_count }
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class.total_count(redis_key)).to eq(0)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe '.totals' do
|
|
|
|
commits = 5
|
|
|
|
merge_requests = 3
|
|
|
|
views = 2
|
2019-12-26 22:10:19 +05:30
|
|
|
previews = 4
|
2020-05-24 23:13:21 +05:30
|
|
|
terminals = 1
|
|
|
|
pipelines = 2
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
before do
|
2019-12-26 22:10:19 +05:30
|
|
|
stub_application_setting(web_ide_clientside_preview_enabled: true)
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
commits.times { described_class.increment_commits_count }
|
|
|
|
merge_requests.times { described_class.increment_merge_requests_count }
|
|
|
|
views.times { described_class.increment_views_count }
|
2019-12-26 22:10:19 +05:30
|
|
|
previews.times { described_class.increment_previews_count }
|
2020-05-24 23:13:21 +05:30
|
|
|
terminals.times { described_class.increment_terminals_count }
|
|
|
|
pipelines.times { described_class.increment_pipelines_count }
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'can report all totals' do
|
|
|
|
expect(described_class.totals).to include(
|
|
|
|
web_ide_commits: commits,
|
|
|
|
web_ide_views: views,
|
2019-12-26 22:10:19 +05:30
|
|
|
web_ide_merge_requests: merge_requests,
|
2020-05-24 23:13:21 +05:30
|
|
|
web_ide_previews: previews,
|
|
|
|
web_ide_terminals: terminals
|
2019-10-12 21:52:04 +05:30
|
|
|
)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|