Merge pull request #4359 from overleaf/ab-example-project-new-split-test

Update example project split test to new framework

GitOrigin-RevId: 9b3f1cb2b7a84d0078abf9c748dcdf9c6c7637e1
This commit is contained in:
Alexandre Bourdin 2021-07-30 10:57:32 +02:00 committed by Copybot
parent 547260b2b2
commit 5b5c7ebd01
3 changed files with 11 additions and 18 deletions

View file

@ -15,7 +15,7 @@ const path = require('path')
const { callbackify } = require('util')
const _ = require('underscore')
const AnalyticsManager = require('../Analytics/AnalyticsManager')
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
const SplitTestV2Handler = require('../SplitTests/SplitTestV2Handler')
const MONTH_NAMES = [
'January',
@ -31,7 +31,7 @@ const MONTH_NAMES = [
'November',
'December',
]
const EXAMPLE_PROJECT_SPLITTEST_ID = 'example-project-v2'
const EXAMPLE_PROJECT_SPLITTEST_ID = 'example-project-v3'
async function createBlankProject(ownerId, projectName, attributes = {}) {
const isImport = attributes && attributes.overleaf
@ -72,28 +72,21 @@ async function createBasicProject(ownerId, projectName) {
async function createExampleProject(ownerId, projectName) {
const project = await _createBlankProject(ownerId, projectName)
const testSegmentation = await SplitTestHandler.promises.getTestSegmentation(
const assignment = await SplitTestV2Handler.promises.getAssignment(
ownerId,
EXAMPLE_PROJECT_SPLITTEST_ID
)
if (testSegmentation.variant === 'example-frog') {
if (assignment.variant === 'example-frog') {
await _addSplitTestExampleProjectFiles(ownerId, projectName, project)
} else {
await _addDefaultExampleProjectFiles(ownerId, projectName, project)
}
if (testSegmentation.enabled) {
AnalyticsManager.recordEvent(ownerId, 'project-created', {
projectId: project._id,
splitTestId: EXAMPLE_PROJECT_SPLITTEST_ID,
splitTestVariantId: testSegmentation.variant,
...assignment.analytics.segmentation,
})
} else {
AnalyticsManager.recordEvent(ownerId, 'project-created', {
projectId: project._id,
})
}
return project
}

View file

@ -14,7 +14,7 @@ class SplitTestCache extends CacheLoader {
}
serialize(value) {
return value.toObject()
return value ? value.toObject() : undefined
}
deserialize(value) {

View file

@ -31,8 +31,8 @@ const BETA_PHASE = 'beta'
*
* @param userId the user's ID
* @param splitTestName the unique name of the split test
* @param options {sync: boolean} - for test purposes only, to force the synchronous update of the user's profile
* @returns {Promise<{analytics: {segmentation: {}}, variant: string}|{analytics: {segmentation: {phase, splitTest, variant: string, versionNumber}}, variant: string}>}
* @param options {Object<sync: boolean>} - for test purposes only, to force the synchronous update of the user's profile
* @returns {Promise<{variant: string, analytics: {segmentation: {splitTest: string, variant: string, phase: string, versionNumber: number}|{}}}>}
*/
async function getAssignment(userId, splitTestName, options) {
const splitTest = await splitTestCache.get(splitTestName)