Merge pull request #24125 from overleaf/rh-current-version-fix

Fix version check for undefined split tests

GitOrigin-RevId: bbbd44a27ca41c5ffac02cb34ac0049a14cd13e4
This commit is contained in:
roo hutton
2025-03-26 08:08:10 +00:00
committed by Copybot
parent 5c6775a8c2
commit 012ff8ad70
2 changed files with 15 additions and 0 deletions
@@ -150,6 +150,14 @@ async function hasUserBeenAssignedToVariant(
const splitTest = await _getSplitTest(splitTestName)
const currentVersion = SplitTestUtils.getCurrentVersion(splitTest)
if (
!userId ||
!SessionManager.isUserLoggedIn(session) ||
!currentVersion?.active
) {
return false
}
// Check the query string for an override, ignoring an invalid value
const queryVariant = query[splitTestName]
if (queryVariant === variant) {
@@ -55,12 +55,17 @@ describe('SplitTestHandler', function () {
}
this.SplitTestSessionHandler = {
collectSessionStats: sinon.stub(),
getCachedVariant: sinon.stub(),
setVariantInCache: sinon.stub(),
}
this.SplitTestUserGetter = {
promises: {
getUser: sinon.stub().resolves(null),
},
}
this.SessionManager = {
isUserLoggedIn: sinon.stub().returns(false),
}
this.SplitTestHandler = SandboxedModule.require(MODULE_PATH, {
requires: {
@@ -72,6 +77,7 @@ describe('SplitTestHandler', function () {
'./LocalsHelper': this.LocalsHelper,
'./SplitTestSessionHandler': this.SplitTestSessionHandler,
'./SplitTestUserGetter': this.SplitTestUserGetter,
'../Authentication/SessionManager': this.SessionManager,
'@overleaf/settings': this.Settings,
},
})
@@ -105,6 +111,7 @@ describe('SplitTestHandler', function () {
},
}
this.SplitTestUserGetter.promises.getUser.resolves(this.user)
this.SessionManager.isUserLoggedIn.returns(true)
this.assignments =
await this.SplitTestHandler.promises.getActiveAssignmentsForUser(
this.user._id