|
@@ -10,6 +10,7 @@ const { SplitTest } = require('../../models/SplitTest')
|
|
|
const UserAnalyticsIdCache = require('../Analytics/UserAnalyticsIdCache')
|
|
const UserAnalyticsIdCache = require('../Analytics/UserAnalyticsIdCache')
|
|
|
const { getAnalyticsIdFromMongoUser } = require('../Analytics/AnalyticsHelper')
|
|
const { getAnalyticsIdFromMongoUser } = require('../Analytics/AnalyticsHelper')
|
|
|
const Features = require('../../infrastructure/Features')
|
|
const Features = require('../../infrastructure/Features')
|
|
|
|
|
+const SplitTestUtils = require('./SplitTestUtils')
|
|
|
|
|
|
|
|
const DEFAULT_VARIANT = 'default'
|
|
const DEFAULT_VARIANT = 'default'
|
|
|
const ALPHA_PHASE = 'alpha'
|
|
const ALPHA_PHASE = 'alpha'
|
|
@@ -191,7 +192,7 @@ async function getActiveAssignmentsForUser(userId) {
|
|
|
*/
|
|
*/
|
|
|
async function _getVariantNames(splitTestName) {
|
|
async function _getVariantNames(splitTestName) {
|
|
|
const splitTest = await SplitTestCache.get(splitTestName)
|
|
const splitTest = await SplitTestCache.get(splitTestName)
|
|
|
- const currentVersion = splitTest?.getCurrentVersion()
|
|
|
|
|
|
|
+ const currentVersion = SplitTestUtils.getCurrentVersion(splitTest)
|
|
|
if (currentVersion?.active) {
|
|
if (currentVersion?.active) {
|
|
|
return currentVersion.variants.map(v => v.name).concat([DEFAULT_VARIANT])
|
|
return currentVersion.variants.map(v => v.name).concat([DEFAULT_VARIANT])
|
|
|
} else {
|
|
} else {
|
|
@@ -208,7 +209,7 @@ async function _getAssignment(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const splitTest = await SplitTestCache.get(splitTestName)
|
|
const splitTest = await SplitTestCache.get(splitTestName)
|
|
|
- const currentVersion = splitTest?.getCurrentVersion()
|
|
|
|
|
|
|
+ const currentVersion = SplitTestUtils.getCurrentVersion(splitTest)
|
|
|
if (!currentVersion?.active) {
|
|
if (!currentVersion?.active) {
|
|
|
return DEFAULT_ASSIGNMENT
|
|
return DEFAULT_ASSIGNMENT
|
|
|
}
|
|
}
|
|
@@ -251,7 +252,7 @@ async function _getAssignment(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function _getAssignmentMetadata(analyticsId, user, splitTest) {
|
|
async function _getAssignmentMetadata(analyticsId, user, splitTest) {
|
|
|
- const currentVersion = splitTest.getCurrentVersion()
|
|
|
|
|
|
|
+ const currentVersion = SplitTestUtils.getCurrentVersion(splitTest)
|
|
|
const phase = currentVersion.phase
|
|
const phase = currentVersion.phase
|
|
|
if (
|
|
if (
|
|
|
(phase === ALPHA_PHASE && !user?.alphaProgram) ||
|
|
(phase === ALPHA_PHASE && !user?.alphaProgram) ||
|
|
@@ -398,10 +399,10 @@ async function _getUser(id) {
|
|
|
async function _loadSplitTestInfoInLocals(locals, splitTestName) {
|
|
async function _loadSplitTestInfoInLocals(locals, splitTestName) {
|
|
|
const splitTest = await SplitTestCache.get(splitTestName)
|
|
const splitTest = await SplitTestCache.get(splitTestName)
|
|
|
if (splitTest) {
|
|
if (splitTest) {
|
|
|
- const phase = splitTest.getCurrentVersion().phase
|
|
|
|
|
|
|
+ const phase = SplitTestUtils.getCurrentVersion(splitTest).phase
|
|
|
LocalsHelper.setSplitTestInfo(locals, splitTestName, {
|
|
LocalsHelper.setSplitTestInfo(locals, splitTestName, {
|
|
|
phase,
|
|
phase,
|
|
|
- badgeInfo: splitTest.toObject().badgeInfo?.[phase],
|
|
|
|
|
|
|
+ badgeInfo: splitTest.badgeInfo?.[phase],
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|