Merge pull request #33482 from overleaf/ar-mixpanel-labs-project
[web/analytics] Send labs user's events to separate mixpanel project GitOrigin-RevId: 42612b71d2d7a082ffbe1ff614499a0b94553b90
This commit is contained in:
@@ -89,10 +89,13 @@ describe('AnalyticsManager', function () {
|
||||
}))
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Analytics/UserAnalyticsIdCache',
|
||||
'../../../../app/src/Features/Analytics/UserAnalyticsDataCache',
|
||||
() => ({
|
||||
default: (ctx.UserAnalyticsIdCache = {
|
||||
getWithMetrics: sinon.stub().resolves(ctx.analyticsId),
|
||||
default: (ctx.UserAnalyticsDataCache = {
|
||||
getAnalyticsId: sinon.stub().resolves(ctx.analyticsId),
|
||||
getAnalyticsData: sinon
|
||||
.stub()
|
||||
.resolves({ analyticsId: ctx.analyticsId, labsProgram: false }),
|
||||
}),
|
||||
})
|
||||
)
|
||||
@@ -388,10 +391,13 @@ describe('AnalyticsManager', function () {
|
||||
}))
|
||||
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Analytics/UserAnalyticsIdCache',
|
||||
'../../../../app/src/Features/Analytics/UserAnalyticsDataCache',
|
||||
() => ({
|
||||
default: (ctx.UserAnalyticsIdCache = {
|
||||
getWithMetrics: sinon.stub().resolves(ctx.analyticsId),
|
||||
default: (ctx.UserAnalyticsDataCache = {
|
||||
getAnalyticsId: sinon.stub().resolves(ctx.analyticsId),
|
||||
getAnalyticsData: sinon
|
||||
.stub()
|
||||
.resolves({ analyticsId: ctx.analyticsId, labsProgram: false }),
|
||||
}),
|
||||
})
|
||||
)
|
||||
@@ -439,7 +445,7 @@ describe('AnalyticsManager', function () {
|
||||
})
|
||||
|
||||
it('sets session.analyticsId with a legacy user session without an analyticsId', async function (ctx) {
|
||||
ctx.UserAnalyticsIdCache.getWithMetrics.resolves(ctx.userId)
|
||||
ctx.UserAnalyticsDataCache.getAnalyticsId.resolves(ctx.userId)
|
||||
ctx.req.session.user = {
|
||||
_id: ctx.userId,
|
||||
analyticsId: undefined,
|
||||
@@ -450,7 +456,7 @@ describe('AnalyticsManager', function () {
|
||||
})
|
||||
|
||||
it('updates session.analyticsId with a legacy user session without an analyticsId if different', async function (ctx) {
|
||||
ctx.UserAnalyticsIdCache.getWithMetrics.resolves(ctx.userId)
|
||||
ctx.UserAnalyticsDataCache.getAnalyticsId.resolves(ctx.userId)
|
||||
ctx.req.session.user = {
|
||||
_id: ctx.userId,
|
||||
analyticsId: undefined,
|
||||
@@ -462,7 +468,7 @@ describe('AnalyticsManager', function () {
|
||||
})
|
||||
|
||||
it('does not update session.analyticsId with a legacy user session without an analyticsId if same', async function (ctx) {
|
||||
ctx.UserAnalyticsIdCache.getWithMetrics.resolves(ctx.userId)
|
||||
ctx.UserAnalyticsDataCache.getAnalyticsId.resolves(ctx.userId)
|
||||
ctx.req.session.user = {
|
||||
_id: ctx.userId,
|
||||
analyticsId: undefined,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { vi } from 'vitest'
|
||||
import sinon from 'sinon'
|
||||
import path from 'node:path'
|
||||
|
||||
const MODULE_PATH = path.join(
|
||||
import.meta.dirname,
|
||||
'../../../../app/src/Features/Analytics/UserAnalyticsDataCache'
|
||||
)
|
||||
|
||||
describe('UserAnalyticsDataCache', function () {
|
||||
beforeEach(async function (ctx) {
|
||||
ctx.userId = 'abc123def456abc123def456'
|
||||
ctx.analyticsId = 'ecdb935a-52f3-4f91-aebc-7a70d2ffbb55'
|
||||
ctx.cacheDeleteSpy = sinon.stub().resolves()
|
||||
|
||||
ctx.UserGetter = {
|
||||
promises: {
|
||||
getUser: sinon.stub().resolves({
|
||||
_id: ctx.userId,
|
||||
analyticsId: ctx.analyticsId,
|
||||
labsProgram: false,
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
vi.doMock('../../../../app/src/Features/User/UserGetter.mjs', () => ({
|
||||
default: ctx.UserGetter,
|
||||
}))
|
||||
|
||||
vi.doMock('@overleaf/metrics', () => ({
|
||||
default: { inc: sinon.stub() },
|
||||
}))
|
||||
|
||||
vi.doMock('cache-flow', () => ({
|
||||
CacheLoader: class {
|
||||
async delete(key) {
|
||||
return ctx.cacheDeleteSpy(key)
|
||||
}
|
||||
|
||||
async getWithMetadata() {
|
||||
return { value: undefined, cached: false, time: 0 }
|
||||
}
|
||||
|
||||
keyToString(key) {
|
||||
return key?.toString()
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
||||
ctx.UserAnalyticsDataCache = (await import(MODULE_PATH)).default
|
||||
})
|
||||
|
||||
describe('invalidateCache', function () {
|
||||
it('should delete the cache entry for the userId', async function (ctx) {
|
||||
await ctx.UserAnalyticsDataCache.invalidateCache(ctx.userId)
|
||||
sinon.assert.calledOnce(ctx.cacheDeleteSpy)
|
||||
sinon.assert.calledWith(ctx.cacheDeleteSpy, ctx.userId)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user