|
|
@@ -47,7 +47,11 @@ async function getSplitTests({ name, phase, type, active, archived }) {
|
|
|
filters.archived = { $ne: true }
|
|
|
}
|
|
|
try {
|
|
|
- return await SplitTest.find(filters).limit(100).exec()
|
|
|
+ return await SplitTest.find(filters)
|
|
|
+ .populate('archivedBy', ['email', 'first_name', 'last_name'])
|
|
|
+ .populate('versions.author', ['email', 'first_name', 'last_name'])
|
|
|
+ .limit(100)
|
|
|
+ .exec()
|
|
|
} catch (error) {
|
|
|
throw OError.tag(error, 'Failed to get split tests list')
|
|
|
}
|
|
|
@@ -55,18 +59,19 @@ async function getSplitTests({ name, phase, type, active, archived }) {
|
|
|
|
|
|
async function getSplitTest(query) {
|
|
|
try {
|
|
|
- return await SplitTest.findOne(query).exec()
|
|
|
+ return await SplitTest.findOne(query)
|
|
|
+ .populate('archivedBy', ['email', 'first_name', 'last_name'])
|
|
|
+ .populate('versions.author', ['email', 'first_name', 'last_name'])
|
|
|
+ .exec()
|
|
|
} catch (error) {
|
|
|
throw OError.tag(error, 'Failed to get split test', { query })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function createSplitTest({
|
|
|
- name,
|
|
|
- configuration,
|
|
|
- badgeInfo = {},
|
|
|
- info = {},
|
|
|
-}) {
|
|
|
+async function createSplitTest(
|
|
|
+ { name, configuration, badgeInfo = {}, info = {} },
|
|
|
+ userId
|
|
|
+) {
|
|
|
const stripedVariants = []
|
|
|
let stripeStart = 0
|
|
|
_checkNewVariantsConfiguration([], configuration.variants)
|
|
|
@@ -102,13 +107,14 @@ async function createSplitTest({
|
|
|
analyticsEnabled:
|
|
|
configuration.active && configuration.analyticsEnabled,
|
|
|
variants: stripedVariants,
|
|
|
+ author: userId,
|
|
|
},
|
|
|
],
|
|
|
})
|
|
|
return _saveSplitTest(splitTest)
|
|
|
}
|
|
|
|
|
|
-async function updateSplitTestConfig(name, configuration) {
|
|
|
+async function updateSplitTestConfig({ name, configuration, comment }, userId) {
|
|
|
const splitTest = await getSplitTest({ name })
|
|
|
if (!splitTest) {
|
|
|
throw new OError(`Cannot update split test '${name}': not found`)
|
|
|
@@ -134,6 +140,8 @@ async function updateSplitTestConfig(name, configuration) {
|
|
|
active: configuration.active,
|
|
|
analyticsEnabled: configuration.active && configuration.analyticsEnabled,
|
|
|
variants: updatedVariants,
|
|
|
+ author: userId,
|
|
|
+ comment,
|
|
|
})
|
|
|
return _saveSplitTest(splitTest)
|
|
|
}
|
|
|
@@ -160,7 +168,7 @@ async function updateSplitTestBadgeInfo(name, badgeInfo) {
|
|
|
return _saveSplitTest(splitTest)
|
|
|
}
|
|
|
|
|
|
-async function switchToNextPhase(name) {
|
|
|
+async function switchToNextPhase({ name, comment }, userId) {
|
|
|
const splitTest = await getSplitTest({ name })
|
|
|
if (!splitTest) {
|
|
|
throw new OError(
|
|
|
@@ -192,11 +200,17 @@ async function switchToNextPhase(name) {
|
|
|
variant.rolloutPercent = 0
|
|
|
variant.rolloutStripes = []
|
|
|
}
|
|
|
+ lastVersionCopy.author = userId
|
|
|
+ lastVersionCopy.comment = comment
|
|
|
+ lastVersionCopy.createdAt = new Date()
|
|
|
splitTest.versions.push(lastVersionCopy)
|
|
|
return _saveSplitTest(splitTest)
|
|
|
}
|
|
|
|
|
|
-async function revertToPreviousVersion(name, versionNumber) {
|
|
|
+async function revertToPreviousVersion(
|
|
|
+ { name, versionNumber, comment },
|
|
|
+ userId
|
|
|
+) {
|
|
|
const splitTest = await getSplitTest({ name })
|
|
|
if (!splitTest) {
|
|
|
throw new OError(
|
|
|
@@ -232,11 +246,13 @@ async function revertToPreviousVersion(name, versionNumber) {
|
|
|
const previousVersionCopy = previousVersion.toObject()
|
|
|
previousVersionCopy.versionNumber = lastVersion.versionNumber + 1
|
|
|
previousVersionCopy.createdAt = new Date()
|
|
|
+ previousVersionCopy.author = userId
|
|
|
+ previousVersionCopy.comment = comment
|
|
|
splitTest.versions.push(previousVersionCopy)
|
|
|
return _saveSplitTest(splitTest)
|
|
|
}
|
|
|
|
|
|
-async function archive(name) {
|
|
|
+async function archive(name, userId) {
|
|
|
const splitTest = await getSplitTest({ name })
|
|
|
if (!splitTest) {
|
|
|
throw new OError(`Cannot archive split test with ID '${name}': not found`)
|
|
|
@@ -246,6 +262,7 @@ async function archive(name) {
|
|
|
}
|
|
|
splitTest.archived = true
|
|
|
splitTest.archivedAt = new Date()
|
|
|
+ splitTest.archivedBy = userId
|
|
|
return _saveSplitTest(splitTest)
|
|
|
}
|
|
|
|
|
|
@@ -320,7 +337,18 @@ function _getTotalRolloutPercentage(variants) {
|
|
|
|
|
|
async function _saveSplitTest(splitTest) {
|
|
|
try {
|
|
|
- return (await splitTest.save()).toObject()
|
|
|
+ const savedSplitTest = await splitTest.save()
|
|
|
+ await savedSplitTest.populate('archivedBy', [
|
|
|
+ 'email',
|
|
|
+ 'first_name',
|
|
|
+ 'last_name',
|
|
|
+ ])
|
|
|
+ await savedSplitTest.populate('versions.author', [
|
|
|
+ 'email',
|
|
|
+ 'first_name',
|
|
|
+ 'last_name',
|
|
|
+ ])
|
|
|
+ return savedSplitTest.toObject()
|
|
|
} catch (error) {
|
|
|
throw OError.tag(error, 'Failed to save split test', {
|
|
|
splitTest: JSON.stringify(splitTest),
|