Merge pull request #13244 from overleaf/msm-fix-split-test-client

[web] Fix split test assignments not sent via LocalsHelper in Server Pro

GitOrigin-RevId: 3a69fda3a4a0e66ecde3772d918d9c6d46e89ecf
This commit is contained in:
Miguel Serrano 2023-05-31 15:24:38 +02:00 committed by Copybot
parent a74eecd110
commit db70128d03
2 changed files with 60 additions and 25 deletions

View file

@ -49,13 +49,12 @@ const DEFAULT_ASSIGNMENT = {
* @returns {Promise<{variant: string, analytics: {segmentation: {splitTest: string, variant: string, phase: string, versionNumber: number}|{}}}>} * @returns {Promise<{variant: string, analytics: {segmentation: {splitTest: string, variant: string, phase: string, versionNumber: number}|{}}}>}
*/ */
async function getAssignment(req, res, splitTestName, { sync = false } = {}) { async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
if (!Features.hasFeature('saas')) {
return _getNonSaasAssignment(splitTestName)
}
const query = req.query || {} const query = req.query || {}
let assignment let assignment
if (!Features.hasFeature('saas')) {
assignment = _getNonSaasAssignment(splitTestName)
} else {
// Check the query string for an override, ignoring an invalid value // Check the query string for an override, ignoring an invalid value
const queryVariant = query[splitTestName] const queryVariant = query[splitTestName]
if (queryVariant) { if (queryVariant) {
@ -81,6 +80,7 @@ async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
sync, sync,
}) })
} }
}
LocalsHelper.setSplitTestVariant( LocalsHelper.setSplitTestVariant(
res.locals, res.locals,

View file

@ -257,6 +257,41 @@ describe('SplitTestHandler', function () {
assert.equal('default', assignment.variant) assert.equal('default', assignment.variant)
}) })
}) })
describe('save assignments to res.locals', function () {
beforeEach(function () {
this.AnalyticsManager.getIdsFromSession.returns({
userId: 'abc123abc123',
})
})
it('when in SaaS mode it should set the variant', async function () {
await this.SplitTestHandler.promises.getAssignment(
this.req,
this.res,
'active-test'
)
expect(this.LocalsHelper.setSplitTestVariant).to.have.been.calledWith(
this.res.locals,
'active-test',
'variant-1'
)
})
it('when not in SaaS mode it should set the default variant', async function () {
this.Settings.overleaf = undefined
await this.SplitTestHandler.promises.getAssignment(
this.req,
this.res,
'active-test'
)
expect(this.LocalsHelper.setSplitTestVariant).to.have.been.calledWith(
this.res.locals,
'active-test',
'default'
)
})
})
}) })
function makeSplitTest( function makeSplitTest(