Commit ff500c73 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'nd/fix-error-when-calling-user-usage-endpoint' into 'master'

Call RedisHllUserEvent only when a user is set

See merge request gitlab-org/gitlab!62560
parents c04dd69f 95b44716
......@@ -866,7 +866,7 @@ const Api = {
},
trackRedisHllUserEvent(event) {
if (!gon.features?.usageDataApi) {
if (!gon.current_user_id || !gon.features?.usageDataApi) {
return null;
}
......
......@@ -1503,17 +1503,23 @@ describe('Api', () => {
'Content-Type': 'application/json',
};
describe('when user is set', () => {
beforeEach(() => {
window.gon.current_user_id = 1;
});
describe('when usage data increment unique users is called with feature flag disabled', () => {
beforeEach(() => {
gon.features = { ...gon.features, usageDataApi: false };
});
it('returns null', () => {
it('returns null and does not call the endpoint', () => {
jest.spyOn(axios, 'post');
mock.onPost(expectedUrl).replyOnce(httpStatus.OK, true);
const result = Api.trackRedisHllUserEvent(event);
expect(result).toEqual(null);
expect(axios.post).toHaveBeenCalledTimes(0);
expect(Api.trackRedisHllUserEvent(event)).toEqual(null);
});
});
......@@ -1534,6 +1540,22 @@ describe('Api', () => {
});
});
describe('when user is not set and feature flag enabled', () => {
beforeEach(() => {
gon.features = { ...gon.features, usageDataApi: true };
});
it('returns null and does not call the endpoint', () => {
jest.spyOn(axios, 'post');
const result = Api.trackRedisHllUserEvent(event);
expect(result).toEqual(null);
expect(axios.post).toHaveBeenCalledTimes(0);
});
});
});
describe('Feature Flag User List', () => {
let expectedUrl;
let projectId;
......
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