Merge pull request #3495 from overleaf/ae-prettier-2

Upgrade Prettier to v2

GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
Alf Eaton
2021-04-15 02:05:22 +00:00
committed by Copybot
parent 930d7ba028
commit 1ebc8a79cb
582 changed files with 20382 additions and 20374 deletions
@@ -6,14 +6,14 @@ const SandboxedModule = require('sandboxed-module')
const Path = require('path')
const { ObjectId } = require('mongodb')
describe('ProjectCreationHandler', function() {
describe('ProjectCreationHandler', function () {
const ownerId = '4eecb1c1bffa66588e0000a1'
const projectName = 'project name goes here'
const projectId = '4eecaffcbffa66588e000008'
const docId = '4eecb17ebffa66588e00003f'
const rootFolderId = '234adfa3r2afe'
beforeEach(function() {
beforeEach(function () {
this.ProjectModel = class Project {
constructor(options) {
if (options == null) {
@@ -81,8 +81,8 @@ describe('ProjectCreationHandler', function() {
})
})
describe('Creating a Blank project', function() {
beforeEach(function() {
describe('Creating a Blank project', function () {
beforeEach(function () {
this.overleafId = 1234
this.HistoryManager.initializeProject = sinon
.stub()
@@ -90,15 +90,15 @@ describe('ProjectCreationHandler', function() {
this.ProjectModel.prototype.save = sinon.stub().callsArg(0)
})
describe('successfully', function() {
it('should save the project', function(done) {
describe('successfully', function () {
it('should save the project', function (done) {
this.handler.createBlankProject(ownerId, projectName, () => {
this.ProjectModel.prototype.save.called.should.equal(true)
done()
})
})
it('should return the project in the callback', function(done) {
it('should return the project in the callback', function (done) {
this.handler.createBlankProject(
ownerId,
projectName,
@@ -114,12 +114,12 @@ describe('ProjectCreationHandler', function() {
)
})
it('should initialize the project overleaf if history id not provided', function(done) {
it('should initialize the project overleaf if history id not provided', function (done) {
this.handler.createBlankProject(ownerId, projectName, done)
this.HistoryManager.initializeProject.calledWith().should.equal(true)
})
it('should set the overleaf id if overleaf id not provided', function(done) {
it('should set the overleaf id if overleaf id not provided', function (done) {
this.handler.createBlankProject(
ownerId,
projectName,
@@ -133,7 +133,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should set the overleaf id if overleaf id provided', function(done) {
it('should set the overleaf id if overleaf id provided', function (done) {
const overleafId = 2345
const attributes = {
overleaf: {
@@ -156,7 +156,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should set the language from the user', function(done) {
it('should set the language from the user', function (done) {
this.handler.createBlankProject(
ownerId,
projectName,
@@ -170,7 +170,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should set the imageName to currentImageName if set and no imageName attribute', function(done) {
it('should set the imageName to currentImageName if set and no imageName attribute', function (done) {
this.Settings.currentImageName = 'mock-image-name'
this.handler.createBlankProject(
ownerId,
@@ -185,7 +185,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should not set the imageName if no currentImageName', function(done) {
it('should not set the imageName if no currentImageName', function (done) {
this.Settings.currentImageName = null
this.handler.createBlankProject(
ownerId,
@@ -200,7 +200,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should set the imageName to the attribute value if set and not overwrite it with the currentImageName', function(done) {
it('should set the imageName to the attribute value if set and not overwrite it with the currentImageName', function (done) {
this.Settings.currentImageName = 'mock-image-name'
const attributes = { imageName: 'attribute-image-name' }
this.handler.createBlankProject(
@@ -217,7 +217,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should not set the overleaf.history.display if not configured in settings', function(done) {
it('should not set the overleaf.history.display if not configured in settings', function (done) {
this.Settings.apis.project_history.displayHistoryForNewProjects = false
this.handler.createBlankProject(
ownerId,
@@ -232,7 +232,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should set the overleaf.history.display if configured in settings', function(done) {
it('should set the overleaf.history.display if configured in settings', function (done) {
this.Settings.apis.project_history.displayHistoryForNewProjects = true
this.handler.createBlankProject(
ownerId,
@@ -247,7 +247,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should send a project-created event to analytics', function(done) {
it('should send a project-created event to analytics', function (done) {
this.handler.createBlankProject(
ownerId,
projectName,
@@ -267,7 +267,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should send a project-created event with template information if provided', function(done) {
it('should send a project-created event with template information if provided', function (done) {
const attributes = {
fromV1TemplateId: 100
}
@@ -292,7 +292,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should send a project-imported event when importing a project', function(done) {
it('should send a project-imported event when importing a project', function (done) {
const attributes = {
overleaf: {
history: {
@@ -321,41 +321,41 @@ describe('ProjectCreationHandler', function() {
})
})
describe('with an error', function() {
beforeEach(function() {
describe('with an error', function () {
beforeEach(function () {
this.ProjectModel.prototype.save = sinon
.stub()
.callsArgWith(0, new Error('something went wrong'))
this.handler.createBlankProject(ownerId, projectName, this.callback)
})
it('should return the error to the callback', function() {
it('should return the error to the callback', function () {
expect(this.callback.args[0][0]).to.exist
})
})
describe('with an invalid name', function() {
beforeEach(function() {
describe('with an invalid name', function () {
beforeEach(function () {
this.ProjectDetailsHandler.validateProjectName = sinon
.stub()
.yields(new Error('bad name'))
this.handler.createBlankProject(ownerId, projectName, this.callback)
})
it('should return the error to the callback', function() {
it('should return the error to the callback', function () {
expect(this.callback.args[0][0]).to.exist
})
it('should not try to create the project', function() {
it('should not try to create the project', function () {
this.ProjectModel.prototype.save.called.should.equal(false)
})
})
})
describe('Creating a basic project', function() {
beforeEach(function() {
describe('Creating a basic project', function () {
beforeEach(function () {
this.project = new this.ProjectModel()
this.handler._buildTemplate = function(
this.handler._buildTemplate = function (
templateName,
user,
projectName,
@@ -376,27 +376,27 @@ describe('ProjectCreationHandler', function() {
this.handler.createBasicProject(ownerId, projectName, this.callback)
})
it('should create a blank project first', function() {
it('should create a blank project first', function () {
this.handler.createBlankProject
.calledWith(ownerId, projectName)
.should.equal(true)
})
it('should create the root document', function() {
it('should create the root document', function () {
this.handler._createRootDoc
.calledWith(this.project, ownerId, ['mainbasic.tex', 'lines'])
.should.equal(true)
})
it('should build the mainbasic.tex template', function() {
it('should build the mainbasic.tex template', function () {
this.handler._buildTemplate
.calledWith('mainbasic.tex', ownerId, projectName)
.should.equal(true)
})
})
describe('Creating a project from a snippet', function() {
beforeEach(function() {
describe('Creating a project from a snippet', function () {
beforeEach(function () {
this.project = new this.ProjectModel()
this.handler.createBlankProject = sinon
.stub()
@@ -412,23 +412,23 @@ describe('ProjectCreationHandler', function() {
)
})
it('should create a blank project first', function() {
it('should create a blank project first', function () {
this.handler.createBlankProject
.calledWith(ownerId, projectName)
.should.equal(true)
})
it('should create the root document', function() {
it('should create the root document', function () {
this.handler._createRootDoc
.calledWith(this.project, ownerId, ['snippet line 1', 'snippet line 2'])
.should.equal(true)
})
})
describe('Creating an example project', function() {
beforeEach(function() {
describe('Creating an example project', function () {
beforeEach(function () {
this.project = new this.ProjectModel()
this.handler._buildTemplate = function(
this.handler._buildTemplate = function (
templateName,
user,
projectName,
@@ -452,19 +452,19 @@ describe('ProjectCreationHandler', function() {
this.handler.createExampleProject(ownerId, projectName, this.callback)
})
it('should create a blank project first', function() {
it('should create a blank project first', function () {
this.handler.createBlankProject
.calledWith(ownerId, projectName)
.should.equal(true)
})
it('should create the root document', function() {
it('should create the root document', function () {
this.handler._createRootDoc
.calledWith(this.project, ownerId, ['main.tex', 'lines'])
.should.equal(true)
})
it('should insert references.bib', function() {
it('should insert references.bib', function () {
this.ProjectEntityUpdateHandler.addDoc
.calledWith(
projectId,
@@ -476,7 +476,7 @@ describe('ProjectCreationHandler', function() {
.should.equal(true)
})
it('should insert universe.jpg', function() {
it('should insert universe.jpg', function () {
this.ProjectEntityUpdateHandler.addFile
.calledWith(
projectId,
@@ -494,21 +494,21 @@ describe('ProjectCreationHandler', function() {
.should.equal(true)
})
it('should build the main.tex template', function() {
it('should build the main.tex template', function () {
this.handler._buildTemplate
.calledWith('main.tex', ownerId, projectName)
.should.equal(true)
})
it('should build the references.bib template', function() {
it('should build the references.bib template', function () {
this.handler._buildTemplate
.calledWith('references.bib', ownerId, projectName)
.should.equal(true)
})
})
describe('_buildTemplate', function() {
beforeEach(function(done) {
describe('_buildTemplate', function () {
beforeEach(function (done) {
this.handler._buildTemplate(
'main.tex',
this.user_id,
@@ -525,36 +525,36 @@ describe('ProjectCreationHandler', function() {
)
})
it('should insert the project name into the template', function(done) {
it('should insert the project name into the template', function (done) {
this.template.indexOf(projectName).should.not.equal(-1)
done()
})
it('should insert the users name into the template', function(done) {
it('should insert the users name into the template', function (done) {
this.template.indexOf(this.user.first_name).should.not.equal(-1)
this.template.indexOf(this.user.last_name).should.not.equal(-1)
done()
})
it('should not have undefined in the template', function(done) {
it('should not have undefined in the template', function (done) {
this.template.indexOf('undefined').should.equal(-1)
done()
})
it('should not have any underscore brackets in the output', function(done) {
it('should not have any underscore brackets in the output', function (done) {
this.template.indexOf('{{').should.equal(-1)
this.template.indexOf('<%=').should.equal(-1)
done()
})
it('should put the year in', function(done) {
it('should put the year in', function (done) {
this.template.indexOf(new Date().getUTCFullYear()).should.not.equal(-1)
done()
})
})
describe('_createRootDoc', function() {
beforeEach(function(done) {
describe('_createRootDoc', function () {
beforeEach(function (done) {
this.project = new this.ProjectModel()
this.handler._createRootDoc(
@@ -565,7 +565,7 @@ describe('ProjectCreationHandler', function() {
)
})
it('should insert main.tex', function() {
it('should insert main.tex', function () {
this.ProjectEntityUpdateHandler.addDoc
.calledWith(
projectId,
@@ -577,7 +577,7 @@ describe('ProjectCreationHandler', function() {
.should.equal(true)
})
it('should set the main doc id', function() {
it('should set the main doc id', function () {
this.ProjectEntityUpdateHandler.setRootDoc
.calledWith(projectId, docId)
.should.equal(true)