mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
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:
parent
a74eecd110
commit
db70128d03
2 changed files with 60 additions and 25 deletions
|
@ -49,13 +49,12 @@ const DEFAULT_ASSIGNMENT = {
|
|||
* @returns {Promise<{variant: string, analytics: {segmentation: {splitTest: string, variant: string, phase: string, versionNumber: number}|{}}}>}
|
||||
*/
|
||||
async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
|
||||
if (!Features.hasFeature('saas')) {
|
||||
return _getNonSaasAssignment(splitTestName)
|
||||
}
|
||||
|
||||
const query = req.query || {}
|
||||
let assignment
|
||||
|
||||
if (!Features.hasFeature('saas')) {
|
||||
assignment = _getNonSaasAssignment(splitTestName)
|
||||
} else {
|
||||
// Check the query string for an override, ignoring an invalid value
|
||||
const queryVariant = query[splitTestName]
|
||||
if (queryVariant) {
|
||||
|
@ -81,6 +80,7 @@ async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
|
|||
sync,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
LocalsHelper.setSplitTestVariant(
|
||||
res.locals,
|
||||
|
|
|
@ -257,6 +257,41 @@ describe('SplitTestHandler', function () {
|
|||
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(
|
||||
|
|
Loading…
Reference in a new issue