Merge pull request #5325 from overleaf/ab-identify-fix

Skip identify job when userId and analyticsId are the same ObjectID

GitOrigin-RevId: 150ac4aab6a33887c0b5ffba8c66cb9ec83f5c88
This commit is contained in:
Jakob Ackermann 2021-10-01 11:23:20 +02:00 committed by Copybot
parent e3ec2fc11c
commit ca8b55def3
2 changed files with 26 additions and 4 deletions

View file

@ -15,7 +15,7 @@ const analyticsUserPropertiesQueue = Queues.getAnalyticsUserPropertiesQueue()
const ONE_MINUTE_MS = 60 * 1000
function identifyUser(userId, analyticsId, isNewUser) {
if (!userId || !analyticsId || userId === analyticsId) {
if (!userId || !analyticsId || userId.toString() === analyticsId.toString()) {
return
}
if (_isAnalyticsDisabled() || _isSmokeTestUser(userId)) {

View file

@ -4,6 +4,7 @@ const sinon = require('sinon')
const MockRequest = require('../helpers/MockRequest')
const MockResponse = require('../helpers/MockResponse')
const { assert } = require('chai')
const { ObjectID } = require('mongodb')
const MODULE_PATH = path.join(
__dirname,
@ -12,7 +13,7 @@ const MODULE_PATH = path.join(
describe('AnalyticsManager', function () {
beforeEach(function () {
this.fakeUserId = '123abc'
this.fakeUserId = 'dbfc9438d14996f73dd172fb'
this.analyticsId = 'ecdb935a-52f3-4f91-aebc-7a70d2ffbb55'
this.Settings = {
analytics: { enabled: true },
@ -74,15 +75,36 @@ describe('AnalyticsManager', function () {
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('userId or analyticsId is missing', function () {
it('userId is missing', function () {
this.AnalyticsManager.identifyUser(undefined, this.analyticsId)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('analyticsId is missing', function () {
this.AnalyticsManager.identifyUser(this.fakeUserId, undefined)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('userId equal analyticsId', function () {
it('userId equals analyticsId', function () {
this.AnalyticsManager.identifyUser(this.fakeUserId, this.fakeUserId)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('Mongo userId equals string userId', function () {
this.AnalyticsManager.identifyUser(
new ObjectID(this.fakeUserId),
this.fakeUserId
)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
it('userId and analyticsId are the same Mongo ID', function () {
this.AnalyticsManager.identifyUser(
new ObjectID(this.fakeUserId),
new ObjectID(this.fakeUserId)
)
sinon.assert.notCalled(this.analyticsEventsQueue.add)
})
})
describe('queues the appropriate message for', function () {