2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Packages::CreateEventService, feature_category: :package_registry do
|
2022-03-02 08:16:31 +05:30
|
|
|
let(:scope) { 'generic' }
|
2021-01-03 14:25:43 +05:30
|
|
|
let(:event_name) { 'push_package' }
|
|
|
|
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
scope: scope,
|
|
|
|
event_name: event_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(nil, user, params).execute }
|
|
|
|
|
|
|
|
describe '#execute' do
|
2021-03-08 18:12:59 +05:30
|
|
|
shared_examples 'redis package unique event creation' do |originator_type, expected_scope|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'tracks the event' do
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(/package/, values: user.id)
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
subject
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
shared_examples 'redis package count event creation' do |originator_type, expected_scope|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'tracks the event' do
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(::Gitlab::UsageDataCounters::PackageEventCounter).to receive(:count).at_least(:once)
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'with a user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it_behaves_like 'redis package unique event creation', 'user', 'generic'
|
|
|
|
it_behaves_like 'redis package count event creation', 'user', 'generic'
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a deploy token' do
|
|
|
|
let(:user) { create(:deploy_token) }
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it_behaves_like 'redis package unique event creation', 'deploy_token', 'generic'
|
|
|
|
it_behaves_like 'redis package count event creation', 'deploy_token', 'generic'
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no user' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it_behaves_like 'redis package count event creation', 'guest', 'generic'
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a package as scope' do
|
|
|
|
let(:scope) { create(:npm_package) }
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
context 'as guest' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it_behaves_like 'redis package count event creation', 'guest', 'npm'
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with user' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it_behaves_like 'redis package unique event creation', 'user', 'npm'
|
|
|
|
it_behaves_like 'redis package count event creation', 'user', 'npm'
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|