diff options
Diffstat (limited to 'spec/services/users/activity_service_spec.rb')
-rw-r--r-- | spec/services/users/activity_service_spec.rb | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/spec/services/users/activity_service_spec.rb b/spec/services/users/activity_service_spec.rb index 47a4b943d83..6c0d93f568a 100644 --- a/spec/services/users/activity_service_spec.rb +++ b/spec/services/users/activity_service_spec.rb @@ -7,9 +7,21 @@ RSpec.describe Users::ActivityService do let(:user) { create(:user, last_activity_on: last_activity_on) } - subject { described_class.new(user) } + subject { described_class.new(author: user) } describe '#execute', :clean_gitlab_redis_shared_state do + shared_examples 'does not update last_activity_on' do + it 'does not update user attribute' do + expect { subject.execute }.not_to change(user, :last_activity_on) + end + + it 'does not track Snowplow event' do + subject.execute + + expect_no_snowplow_event + end + end + context 'when last activity is nil' do let(:last_activity_on) { nil } @@ -41,13 +53,29 @@ RSpec.describe Users::ActivityService do subject.execute end + + it_behaves_like 'Snowplow event tracking with RedisHLL context' do + subject(:record_activity) { described_class.new(author: user, namespace: namespace, project: project).execute } + + let(:feature_flag_name) { :route_hll_to_snowplow_phase3 } + let(:category) { described_class.name } + let(:action) { 'perform_action' } + let(:label) { 'redis_hll_counters.manage.unique_active_users_monthly' } + let(:namespace) { build(:group) } + let(:project) { build(:project) } + let(:context) do + payload = Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, + event: 'unique_active_user').to_context + [Gitlab::Json.dump(payload)] + end + end end context 'when a bad object is passed' do let(:fake_object) { double(username: 'hello') } it 'does not record activity' do - service = described_class.new(fake_object) + service = described_class.new(author: fake_object) expect(service).not_to receive(:record_activity) @@ -58,9 +86,7 @@ RSpec.describe Users::ActivityService do context 'when last activity is today' do let(:last_activity_on) { Date.today } - it 'does not update last_activity_on' do - expect { subject.execute }.not_to change(user, :last_activity_on) - end + it_behaves_like 'does not update last_activity_on' it 'does not try to obtain ExclusiveLease' do expect(Gitlab::ExclusiveLease).not_to receive(:new).with("activity_service:#{user.id}", anything) @@ -76,19 +102,17 @@ RSpec.describe Users::ActivityService do allow(Gitlab::Database).to receive(:read_only?).and_return(true) end - it 'does not update last_activity_on' do - expect { subject.execute }.not_to change(user, :last_activity_on) - end + it_behaves_like 'does not update last_activity_on' end context 'when a lease could not be obtained' do let(:last_activity_on) { nil } - it 'does not update last_activity_on' do + before do stub_exclusive_lease_taken("activity_service:#{user.id}", timeout: 1.minute.to_i) - - expect { subject.execute }.not_to change(user, :last_activity_on) end + + it_behaves_like 'does not update last_activity_on' end end @@ -104,7 +128,7 @@ RSpec.describe Users::ActivityService do end let(:service) do - service = described_class.new(user) + service = described_class.new(author: user) ::Gitlab::Database::LoadBalancing::Session.clear_session @@ -123,7 +147,7 @@ RSpec.describe Users::ActivityService do end context 'database load balancing is not configured' do - let(:service) { described_class.new(user) } + let(:service) { described_class.new(author: user) } it 'updates user without error' do service.execute |