mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
b770feadc8
commit
af9a3d4fb7
6 changed files with 34 additions and 70 deletions
|
@ -15,7 +15,6 @@ const path = require('path')
|
|||
const { callbackify } = require('util')
|
||||
const _ = require('underscore')
|
||||
const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
||||
const SplitTestV2Handler = require('../SplitTests/SplitTestV2Handler')
|
||||
|
||||
const MONTH_NAMES = [
|
||||
'January',
|
||||
|
@ -31,7 +30,6 @@ const MONTH_NAMES = [
|
|||
'November',
|
||||
'December',
|
||||
]
|
||||
const EXAMPLE_PROJECT_SPLITTEST_ID = 'example-project-v3'
|
||||
|
||||
async function createBlankProject(ownerId, projectName, attributes = {}) {
|
||||
const isImport = attributes && attributes.overleaf
|
||||
|
@ -61,76 +59,39 @@ async function createProjectFromSnippet(ownerId, projectName, docLines) {
|
|||
|
||||
async function createBasicProject(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', {
|
||||
projectId: project._id,
|
||||
})
|
||||
const docLines = await _buildTemplate('mainbasic.tex', ownerId, projectName)
|
||||
await _createRootDoc(project, ownerId, docLines)
|
||||
|
||||
return project
|
||||
}
|
||||
|
||||
async function createExampleProject(ownerId, projectName) {
|
||||
const project = await _createBlankProject(ownerId, projectName)
|
||||
|
||||
const assignment = await SplitTestV2Handler.promises.getAssignment(
|
||||
ownerId,
|
||||
EXAMPLE_PROJECT_SPLITTEST_ID
|
||||
)
|
||||
|
||||
if (assignment.variant === 'example-frog') {
|
||||
await _addSplitTestExampleProjectFiles(ownerId, projectName, project)
|
||||
} else {
|
||||
await _addDefaultExampleProjectFiles(ownerId, projectName, project)
|
||||
}
|
||||
await _addExampleProjectFiles(ownerId, projectName, project)
|
||||
|
||||
AnalyticsManager.recordEvent(ownerId, 'project-created', {
|
||||
projectId: project._id,
|
||||
...assignment.analytics.segmentation,
|
||||
})
|
||||
|
||||
return project
|
||||
}
|
||||
|
||||
async function _addDefaultExampleProjectFiles(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) {
|
||||
async function _addExampleProjectFiles(ownerId, projectName, project) {
|
||||
const mainDocLines = await _buildTemplate(
|
||||
'test-example-project/main.tex',
|
||||
'example-project/main.tex',
|
||||
ownerId,
|
||||
projectName
|
||||
)
|
||||
await _createRootDoc(project, ownerId, mainDocLines)
|
||||
|
||||
const bibDocLines = await _buildTemplate(
|
||||
'test-example-project/sample.bib',
|
||||
'example-project/sample.bib',
|
||||
ownerId,
|
||||
projectName
|
||||
)
|
||||
|
@ -143,8 +104,7 @@ async function _addSplitTestExampleProjectFiles(ownerId, projectName, project) {
|
|||
)
|
||||
|
||||
const frogPath = path.resolve(
|
||||
__dirname +
|
||||
'/../../../templates/project_files/test-example-project/frog.jpg'
|
||||
__dirname + '/../../../templates/project_files/example-project/frog.jpg'
|
||||
)
|
||||
await ProjectEntityUpdateHandler.promises.addFile(
|
||||
project._id,
|
||||
|
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
|
@ -45,30 +45,34 @@ async function _createRootDoc(project, ownerId, docLines) {
|
|||
}
|
||||
|
||||
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)
|
||||
|
||||
const referenceDocLines = await _buildTemplate(
|
||||
'references.bib',
|
||||
const bibDocLines = await _buildTemplate(
|
||||
'example-project/sample.bib',
|
||||
ownerId,
|
||||
projectName
|
||||
)
|
||||
await ProjectEntityUpdateHandler.promises.addDoc(
|
||||
project._id,
|
||||
project.rootFolder[0]._id,
|
||||
'references.bib',
|
||||
referenceDocLines,
|
||||
'sample.bib',
|
||||
bibDocLines,
|
||||
ownerId
|
||||
)
|
||||
|
||||
const universePath = path.resolve(
|
||||
__dirname + '/../app/templates/project_files/universe.jpg'
|
||||
const frogPath = path.resolve(
|
||||
__dirname + '/../app/templates/project_files/example-project/frog.jpg'
|
||||
)
|
||||
await ProjectEntityUpdateHandler.promises.addFile(
|
||||
project._id,
|
||||
project.rootFolder[0]._id,
|
||||
'universe.jpg',
|
||||
universePath,
|
||||
'frog.jpg',
|
||||
frogPath,
|
||||
null,
|
||||
ownerId
|
||||
)
|
||||
|
|
|
@ -65,11 +65,11 @@ describe('ProjectDuplicateNames', function () {
|
|||
)
|
||||
this.refBibDoc = _.find(
|
||||
project.rootFolder[0].docs,
|
||||
doc => doc.name === 'references.bib'
|
||||
doc => doc.name === 'sample.bib'
|
||||
)
|
||||
this.imageFile = _.find(
|
||||
project.rootFolder[0].fileRefs,
|
||||
file => file.name === 'universe.jpg'
|
||||
file => file.name === 'frog.jpg'
|
||||
)
|
||||
this.rootFolderId = project.rootFolder[0]._id.toString()
|
||||
// create a folder called 'testfolder'
|
||||
|
@ -181,7 +181,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
{
|
||||
uri: `/project/${this.example_project_id}/doc`,
|
||||
json: {
|
||||
name: 'universe.jpg',
|
||||
name: 'frog.jpg',
|
||||
parent_folder_id: this.rootFolderId,
|
||||
},
|
||||
},
|
||||
|
@ -203,7 +203,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
{
|
||||
uri: `/project/${this.example_project_id}/folder`,
|
||||
json: {
|
||||
name: 'universe.jpg',
|
||||
name: 'frog.jpg',
|
||||
parent_folder_id: this.rootFolderId,
|
||||
},
|
||||
},
|
||||
|
@ -227,7 +227,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
json: true,
|
||||
qs: {
|
||||
folder_id: this.rootFolderId,
|
||||
qqfilename: 'universe.jpg',
|
||||
qqfilename: 'frog.jpg',
|
||||
},
|
||||
formData: {
|
||||
qqfile: {
|
||||
|
@ -235,7 +235,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
Path.resolve(__dirname + '/../files/1pixel.png')
|
||||
),
|
||||
options: {
|
||||
filename: 'universe.jpg',
|
||||
filename: 'frog.jpg',
|
||||
contentType: 'image/jpeg',
|
||||
},
|
||||
},
|
||||
|
@ -310,7 +310,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
json: true,
|
||||
qs: {
|
||||
folder_id: this.rootFolderId,
|
||||
qqfilename: 'universe.jpg',
|
||||
qqfilename: 'frog.jpg',
|
||||
},
|
||||
formData: {
|
||||
qqfile: {
|
||||
|
@ -409,7 +409,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
{
|
||||
uri: `/project/${this.example_project_id}/doc/${this.refBibDoc._id}/rename`,
|
||||
json: {
|
||||
name: 'universe.jpg',
|
||||
name: 'frog.jpg',
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
|
@ -430,7 +430,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
{
|
||||
uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/rename`,
|
||||
json: {
|
||||
name: 'universe.jpg',
|
||||
name: 'frog.jpg',
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
|
@ -451,7 +451,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
{
|
||||
uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/rename`,
|
||||
json: {
|
||||
name: 'universe.jpg',
|
||||
name: 'frog.jpg',
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
|
@ -547,7 +547,7 @@ describe('ProjectDuplicateNames', function () {
|
|||
{
|
||||
uri: `/project/${this.example_project_id}/doc`,
|
||||
json: {
|
||||
name: 'universe.jpg',
|
||||
name: 'frog.jpg',
|
||||
parent_folder_id: this.testFolderId,
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue