diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-26 09:10:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-26 09:10:34 +0300 |
commit | fb553bbc1899eddaddb07cd9685cdabffbed9962 (patch) | |
tree | 473f1ad59a01e98d6ee1a04f462e524bb585f1e4 /spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb | |
parent | a51e52bf5b7a708255a858ca51de8d4a6e58b074 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb b/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb new file mode 100644 index 00000000000..d86b8a23dc7 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redis_shared_state do + let(:time) { Time.zone.now } + let(:action) { 'example_action' } + + def track_action(params) + described_class.track_action(params) + end + + def count_unique(params) + described_class.count_unique(params) + end + + context 'tracking an event' do + context 'when tracking successfully' do + it 'tracks and counts the events as expected' do + stub_application_setting(usage_ping_enabled: true) + + aggregate_failures do + expect(track_action(action: action, author_id: 1)).to be_truthy + expect(track_action(action: action, author_id: 1)).to be_truthy + expect(track_action(action: action, author_id: 2)).to be_truthy + expect(track_action(action: action, author_id: 3, time: time - 3.days)).to be_truthy + + expect(count_unique(action: action, date_from: time, date_to: Date.today)).to eq(2) + expect(count_unique(action: action, date_from: time - 5.days, date_to: Date.tomorrow)).to eq(3) + end + end + end + + context 'when tracking unsuccessfully' do + it 'does not track the event' do + stub_application_setting(usage_ping_enabled: false) + + expect(track_action(action: action, author_id: 2)).to be_nil + expect(count_unique(action: action, date_from: time, date_to: Date.today)).to eq(0) + end + end + end +end |