Merge pull request #23939 from overleaf/rh-cio-analytics-split-test

Only send events to customer.io if in campaign split test

GitOrigin-RevId: 572ad5efdfc1e86f525722c6a425fa1454f2cf3a
This commit is contained in:
roo hutton
2025-03-06 08:54:24 +00:00
committed by Copybot
parent 4441f42dea
commit 27e2adecab
8 changed files with 180 additions and 8 deletions
@@ -14,7 +14,7 @@ const MODULE_PATH = Path.join(
describe('SplitTestHandler', function () {
beforeEach(function () {
this.splitTests = [
makeSplitTest('active-test'),
makeSplitTest('active-test', { versionNumber: 2 }),
makeSplitTest('not-active-test', { active: false }),
makeSplitTest('legacy-test'),
makeSplitTest('no-analytics-test-1', { analyticsEnabled: false }),
@@ -109,6 +109,27 @@ describe('SplitTestHandler', function () {
await this.SplitTestHandler.promises.getActiveAssignmentsForUser(
this.user._id
)
this.explicitAssignments =
await this.SplitTestHandler.promises.getActiveAssignmentsForUser(
this.user._id,
false,
true
)
this.assignedToActiveTest =
await this.SplitTestHandler.promises.hasUserBeenAssignedToVariant(
this.req,
this.user._id,
'active-test',
'variant-1'
)
this.assignedToActiveTestAnyVersion =
await this.SplitTestHandler.promises.hasUserBeenAssignedToVariant(
this.req,
this.user._id,
'active-test',
'variant-1',
true
)
})
it('handles the legacy assignment format', function () {
@@ -123,7 +144,15 @@ describe('SplitTestHandler', function () {
expect(this.assignments['active-test']).to.deep.equal({
variantName: 'variant-1',
phase: 'release',
versionNumber: 1,
versionNumber: 2,
})
})
it('returns the explicit assignment for each active test', function () {
expect(this.explicitAssignments['active-test']).to.deep.equal({
variantName: 'variant-1',
phase: 'release',
versionNumber: 2,
assignedAt: 'active-test-assigned-at',
})
})
@@ -144,6 +173,14 @@ describe('SplitTestHandler', function () {
})
})
it('shows user has been assigned to previous version of variant', function () {
expect(this.assignedToActiveTestAnyVersion).to.be.true
})
it('shows user has not been explicitly assigned to current version of variant', function () {
expect(this.assignedToActiveTest).to.be.false
})
it('does not return assignments for unknown tests', function () {
expect(this.assignments).not.to.have.property('unknown-test')
})
@@ -171,6 +208,19 @@ describe('SplitTestHandler', function () {
await this.SplitTestHandler.promises.getActiveAssignmentsForUser(
this.user._id
)
this.explicitAssignments =
await this.SplitTestHandler.promises.getActiveAssignmentsForUser(
this.user._id,
false,
true
)
this.assignedToActiveTest =
await this.SplitTestHandler.promises.hasUserBeenAssignedToVariant(
this.req,
this.user._id,
'active-test',
'variant-1'
)
})
it('returns current assignments', function () {
@@ -178,7 +228,7 @@ describe('SplitTestHandler', function () {
'active-test': {
phase: 'release',
variantName: 'variant-1',
versionNumber: 1,
versionNumber: 2,
},
'legacy-test': {
phase: 'release',
@@ -202,6 +252,10 @@ describe('SplitTestHandler', function () {
},
})
})
it('shows user not assigned to variant', function () {
expect(this.assignedToActiveTest).to.be.false
})
})
describe('with settings overrides', function () {