Commit 603cbbe0 authored by alinamihaila's avatar alinamihaila

Make tests consistent

Update docs
parent 95cf4a76
......@@ -295,7 +295,7 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
Arguments:
- `event_name`: event name.
- `values`: values we count unique events
- `values`: values counted, one value or array of values.
Example usage:
......
......@@ -537,11 +537,14 @@ module API
)
end
# @param event_name [String] the event name
# @param values [Array|String] the values counted
def increment_unique_values(event_name, values)
raise "values is empty" unless values.present?
feature_name = "usage_data_#{event_name}"
raise "Feature #{feature_name} not enabled" unless Feature.enabled?(feature_name)
raise "Usage ping not enabled" unless Gitlab::CurrentSettings.usage_ping_enabled?
raise "values is empty" unless values.present?
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(values, event_name)
rescue => error
......
......@@ -190,7 +190,7 @@ RSpec.describe API::Helpers do
end
describe '#increment_unique_values' do
let(:value) { "9f302fea-f828-4ca9-aef4-e10bd723c0b3" }
let(:value) { '9f302fea-f828-4ca9-aef4-e10bd723c0b3' }
let(:event_name) { 'my_event' }
let(:unknown_event) { 'unknown' }
let(:feature) { "usage_data_#{event_name}" }
......@@ -222,6 +222,14 @@ RSpec.describe API::Helpers do
subject.increment_unique_values(unknown_event, value)
end
it 'log an exception for nil values' do
stub_application_setting(usage_ping_enabled: true)
expect(Rails.logger).to receive(:warn).with("Redis tracking event failed for event: #{unknown_event}, message: values is empty")
subject.increment_unique_values(unknown_event, nil)
end
end
context 'with feature disabled' do
......@@ -229,7 +237,7 @@ RSpec.describe API::Helpers do
stub_feature_flags(feature => false)
end
it "logs an exception" do
it 'logs an exception' do
expect(Rails.logger).to receive(:warn).with("Redis tracking event failed for event: #{event_name}, message: Feature #{feature} not enabled")
subject.increment_unique_values(event_name, value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment