Merge pull request #4818 from overleaf/ab-clean-example-project-split-test

Cleanup example project split test and set variant as new template

GitOrigin-RevId: 6d023233077b856f0f9a755eb1a0b60b66b4335f
This commit is contained in:
June Kelly 2021-08-19 10:37:25 +01:00 committed by Copybot
parent b770feadc8
commit af9a3d4fb7
6 changed files with 34 additions and 70 deletions

View file

@ -15,7 +15,6 @@ const path = require('path')
const { callbackify } = require('util') const { callbackify } = require('util')
const _ = require('underscore') const _ = require('underscore')
const AnalyticsManager = require('../Analytics/AnalyticsManager') const AnalyticsManager = require('../Analytics/AnalyticsManager')
const SplitTestV2Handler = require('../SplitTests/SplitTestV2Handler')
const MONTH_NAMES = [ const MONTH_NAMES = [
'January', 'January',
@ -31,7 +30,6 @@ const MONTH_NAMES = [
'November', 'November',
'December', 'December',
] ]
const EXAMPLE_PROJECT_SPLITTEST_ID = 'example-project-v3'
async function createBlankProject(ownerId, projectName, attributes = {}) { async function createBlankProject(ownerId, projectName, attributes = {}) {
const isImport = attributes && attributes.overleaf const isImport = attributes && attributes.overleaf
@ -61,76 +59,39 @@ async function createProjectFromSnippet(ownerId, projectName, docLines) {
async function createBasicProject(ownerId, projectName) { async function createBasicProject(ownerId, projectName) {
const project = await _createBlankProject(ownerId, projectName) const project = await _createBlankProject(ownerId, projectName)
const docLines = await _buildTemplate('mainbasic.tex', ownerId, projectName)
await _createRootDoc(project, ownerId, docLines)
AnalyticsManager.recordEvent(ownerId, 'project-created', { AnalyticsManager.recordEvent(ownerId, 'project-created', {
projectId: project._id, projectId: project._id,
}) })
const docLines = await _buildTemplate('mainbasic.tex', ownerId, projectName)
await _createRootDoc(project, ownerId, docLines)
return project return project
} }
async function createExampleProject(ownerId, projectName) { async function createExampleProject(ownerId, projectName) {
const project = await _createBlankProject(ownerId, projectName) const project = await _createBlankProject(ownerId, projectName)
const assignment = await SplitTestV2Handler.promises.getAssignment( await _addExampleProjectFiles(ownerId, projectName, project)
ownerId,
EXAMPLE_PROJECT_SPLITTEST_ID
)
if (assignment.variant === 'example-frog') {
await _addSplitTestExampleProjectFiles(ownerId, projectName, project)
} else {
await _addDefaultExampleProjectFiles(ownerId, projectName, project)
}
AnalyticsManager.recordEvent(ownerId, 'project-created', { AnalyticsManager.recordEvent(ownerId, 'project-created', {
projectId: project._id, projectId: project._id,
...assignment.analytics.segmentation,
}) })
return project return project
} }
async function _addDefaultExampleProjectFiles(ownerId, projectName, project) { async function _addExampleProjectFiles(ownerId, projectName, project) {
const mainDocLines = await _buildTemplate('main.tex', ownerId, projectName)
await _createRootDoc(project, ownerId, mainDocLines)
const referenceDocLines = await _buildTemplate(
'references.bib',
ownerId,
projectName
)
await ProjectEntityUpdateHandler.promises.addDoc(
project._id,
project.rootFolder[0]._id,
'references.bib',
referenceDocLines,
ownerId
)
const universePath = path.resolve(
__dirname + '/../../../templates/project_files/universe.jpg'
)
await ProjectEntityUpdateHandler.promises.addFile(
project._id,
project.rootFolder[0]._id,
'universe.jpg',
universePath,
null,
ownerId
)
}
async function _addSplitTestExampleProjectFiles(ownerId, projectName, project) {
const mainDocLines = await _buildTemplate( const mainDocLines = await _buildTemplate(
'test-example-project/main.tex', 'example-project/main.tex',
ownerId, ownerId,
projectName projectName
) )
await _createRootDoc(project, ownerId, mainDocLines) await _createRootDoc(project, ownerId, mainDocLines)
const bibDocLines = await _buildTemplate( const bibDocLines = await _buildTemplate(
'test-example-project/sample.bib', 'example-project/sample.bib',
ownerId, ownerId,
projectName projectName
) )
@ -143,8 +104,7 @@ async function _addSplitTestExampleProjectFiles(ownerId, projectName, project) {
) )
const frogPath = path.resolve( const frogPath = path.resolve(
__dirname + __dirname + '/../../../templates/project_files/example-project/frog.jpg'
'/../../../templates/project_files/test-example-project/frog.jpg'
) )
await ProjectEntityUpdateHandler.promises.addFile( await ProjectEntityUpdateHandler.promises.addFile(
project._id, project._id,

View file

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

View file

@ -45,30 +45,34 @@ async function _createRootDoc(project, ownerId, docLines) {
} }
async function _addDefaultExampleProjectFiles(ownerId, projectName, project) { async function _addDefaultExampleProjectFiles(ownerId, projectName, project) {
const mainDocLines = await _buildTemplate('main.tex', ownerId, projectName) const mainDocLines = await _buildTemplate(
'example-project/main.tex',
ownerId,
projectName
)
await _createRootDoc(project, ownerId, mainDocLines) await _createRootDoc(project, ownerId, mainDocLines)
const referenceDocLines = await _buildTemplate( const bibDocLines = await _buildTemplate(
'references.bib', 'example-project/sample.bib',
ownerId, ownerId,
projectName projectName
) )
await ProjectEntityUpdateHandler.promises.addDoc( await ProjectEntityUpdateHandler.promises.addDoc(
project._id, project._id,
project.rootFolder[0]._id, project.rootFolder[0]._id,
'references.bib', 'sample.bib',
referenceDocLines, bibDocLines,
ownerId ownerId
) )
const universePath = path.resolve( const frogPath = path.resolve(
__dirname + '/../app/templates/project_files/universe.jpg' __dirname + '/../app/templates/project_files/example-project/frog.jpg'
) )
await ProjectEntityUpdateHandler.promises.addFile( await ProjectEntityUpdateHandler.promises.addFile(
project._id, project._id,
project.rootFolder[0]._id, project.rootFolder[0]._id,
'universe.jpg', 'frog.jpg',
universePath, frogPath,
null, null,
ownerId ownerId
) )

View file

@ -65,11 +65,11 @@ describe('ProjectDuplicateNames', function () {
) )
this.refBibDoc = _.find( this.refBibDoc = _.find(
project.rootFolder[0].docs, project.rootFolder[0].docs,
doc => doc.name === 'references.bib' doc => doc.name === 'sample.bib'
) )
this.imageFile = _.find( this.imageFile = _.find(
project.rootFolder[0].fileRefs, project.rootFolder[0].fileRefs,
file => file.name === 'universe.jpg' file => file.name === 'frog.jpg'
) )
this.rootFolderId = project.rootFolder[0]._id.toString() this.rootFolderId = project.rootFolder[0]._id.toString()
// create a folder called 'testfolder' // create a folder called 'testfolder'
@ -181,7 +181,7 @@ describe('ProjectDuplicateNames', function () {
{ {
uri: `/project/${this.example_project_id}/doc`, uri: `/project/${this.example_project_id}/doc`,
json: { json: {
name: 'universe.jpg', name: 'frog.jpg',
parent_folder_id: this.rootFolderId, parent_folder_id: this.rootFolderId,
}, },
}, },
@ -203,7 +203,7 @@ describe('ProjectDuplicateNames', function () {
{ {
uri: `/project/${this.example_project_id}/folder`, uri: `/project/${this.example_project_id}/folder`,
json: { json: {
name: 'universe.jpg', name: 'frog.jpg',
parent_folder_id: this.rootFolderId, parent_folder_id: this.rootFolderId,
}, },
}, },
@ -227,7 +227,7 @@ describe('ProjectDuplicateNames', function () {
json: true, json: true,
qs: { qs: {
folder_id: this.rootFolderId, folder_id: this.rootFolderId,
qqfilename: 'universe.jpg', qqfilename: 'frog.jpg',
}, },
formData: { formData: {
qqfile: { qqfile: {
@ -235,7 +235,7 @@ describe('ProjectDuplicateNames', function () {
Path.resolve(__dirname + '/../files/1pixel.png') Path.resolve(__dirname + '/../files/1pixel.png')
), ),
options: { options: {
filename: 'universe.jpg', filename: 'frog.jpg',
contentType: 'image/jpeg', contentType: 'image/jpeg',
}, },
}, },
@ -310,7 +310,7 @@ describe('ProjectDuplicateNames', function () {
json: true, json: true,
qs: { qs: {
folder_id: this.rootFolderId, folder_id: this.rootFolderId,
qqfilename: 'universe.jpg', qqfilename: 'frog.jpg',
}, },
formData: { formData: {
qqfile: { qqfile: {
@ -409,7 +409,7 @@ describe('ProjectDuplicateNames', function () {
{ {
uri: `/project/${this.example_project_id}/doc/${this.refBibDoc._id}/rename`, uri: `/project/${this.example_project_id}/doc/${this.refBibDoc._id}/rename`,
json: { json: {
name: 'universe.jpg', name: 'frog.jpg',
}, },
}, },
(err, res, body) => { (err, res, body) => {
@ -430,7 +430,7 @@ describe('ProjectDuplicateNames', function () {
{ {
uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/rename`, uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/rename`,
json: { json: {
name: 'universe.jpg', name: 'frog.jpg',
}, },
}, },
(err, res, body) => { (err, res, body) => {
@ -451,7 +451,7 @@ describe('ProjectDuplicateNames', function () {
{ {
uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/rename`, uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/rename`,
json: { json: {
name: 'universe.jpg', name: 'frog.jpg',
}, },
}, },
(err, res, body) => { (err, res, body) => {
@ -547,7 +547,7 @@ describe('ProjectDuplicateNames', function () {
{ {
uri: `/project/${this.example_project_id}/doc`, uri: `/project/${this.example_project_id}/doc`,
json: { json: {
name: 'universe.jpg', name: 'frog.jpg',
parent_folder_id: this.testFolderId, parent_folder_id: this.testFolderId,
}, },
}, },