2019-05-29 05:21:06 -04:00
|
|
|
|
const { expect } = require('chai')
|
|
|
|
|
const mkdirp = require('mkdirp')
|
2020-09-23 04:49:26 -04:00
|
|
|
|
const { ObjectId } = require('mongodb')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const Path = require('path')
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
|
const _ = require('underscore')
|
|
|
|
|
|
2020-02-27 07:46:37 -05:00
|
|
|
|
const { Project } = require('../../../app/src/models/Project')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
|
|
|
|
|
|
|
|
|
|
const User = require('./helpers/User')
|
2021-04-06 05:15:00 -04:00
|
|
|
|
const MockDocStoreApiClass = require('./mocks/MockDocstoreApi')
|
2021-02-25 07:22:24 -05:00
|
|
|
|
const MockDocUpdaterApiClass = require('./mocks/MockDocUpdaterApi')
|
|
|
|
|
|
2021-04-06 05:15:00 -04:00
|
|
|
|
let MockDocStoreApi, MockDocUpdaterApi
|
2021-02-25 07:22:24 -05:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
before(function () {
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi = MockDocUpdaterApiClass.instance()
|
2021-04-06 05:15:00 -04:00
|
|
|
|
MockDocStoreApi = MockDocStoreApiClass.instance()
|
2021-02-25 07:22:24 -05:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('ProjectStructureChanges', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let owner
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner = new User()
|
|
|
|
|
owner.login(done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function createExampleProject(owner, callback) {
|
|
|
|
|
owner.createProject(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'example-project',
|
|
|
|
|
{ template: 'example' },
|
|
|
|
|
(error, projectId) => {
|
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(projectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
const rootFolderId = project.rootFolder[0]._id.toString()
|
|
|
|
|
callback(null, projectId, rootFolderId)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function createExampleDoc(owner, projectId, callback) {
|
|
|
|
|
ProjectGetter.getProject(projectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `project/${projectId}/doc`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
name: 'new.tex',
|
2021-04-27 03:52:58 -04:00
|
|
|
|
parent_folder_id: project.rootFolder[0]._id,
|
|
|
|
|
},
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(new Error(`failed to add doc ${res.statusCode}`))
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
callback(null, body._id)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function createExampleFolder(owner, projectId, callback) {
|
|
|
|
|
owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `project/${projectId}/folder`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
|
name: 'foo',
|
|
|
|
|
},
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(new Error(`failed to add doc ${res.statusCode}`))
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
callback(null, body._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function uploadFile(
|
|
|
|
|
owner,
|
|
|
|
|
projectId,
|
|
|
|
|
folderId,
|
|
|
|
|
file,
|
|
|
|
|
name,
|
|
|
|
|
contentType,
|
|
|
|
|
callback
|
|
|
|
|
) {
|
2021-01-11 06:58:16 -05:00
|
|
|
|
owner.uploadFileInProject(
|
|
|
|
|
projectId,
|
|
|
|
|
folderId,
|
|
|
|
|
file,
|
|
|
|
|
name,
|
|
|
|
|
contentType,
|
|
|
|
|
callback
|
2019-08-06 08:20:41 -04:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function uploadExampleFile(owner, projectId, folderId, callback) {
|
2021-01-11 06:58:16 -05:00
|
|
|
|
owner.uploadExampleFileInProject(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
projectId,
|
|
|
|
|
folderId,
|
|
|
|
|
'1pixel.png',
|
|
|
|
|
callback
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function uploadExampleProject(owner, zipFilename, options, callback) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
callback = options
|
|
|
|
|
options = {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const zipFile = fs.createReadStream(
|
|
|
|
|
Path.resolve(Path.join(__dirname, '..', 'files', zipFilename))
|
|
|
|
|
)
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
|
|
|
|
uri: 'project/new/upload',
|
|
|
|
|
formData: {
|
2021-04-27 03:52:58 -04:00
|
|
|
|
qqfile: zipFile,
|
|
|
|
|
},
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
!options.allowBadStatus &&
|
|
|
|
|
(res.statusCode < 200 || res.statusCode >= 300)
|
|
|
|
|
) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return new Error(`failed to upload project ${res.statusCode}`)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
callback(null, JSON.parse(body).project_id, res)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function moveItem(owner, projectId, type, itemId, folderId, callback) {
|
2021-01-11 06:58:16 -05:00
|
|
|
|
owner.moveItemInProject(projectId, type, itemId, folderId, callback)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function renameItem(owner, projectId, type, itemId, name, callback) {
|
2021-01-11 06:58:16 -05:00
|
|
|
|
owner.renameItemInProject(projectId, type, itemId, name, callback)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function deleteItem(owner, projectId, type, itemId, callback) {
|
2021-01-11 06:58:16 -05:00
|
|
|
|
owner.deleteItemInProject(projectId, type, itemId, callback)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function verifyVersionIncremented(
|
|
|
|
|
projectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
updateVersion,
|
|
|
|
|
increment,
|
|
|
|
|
callback
|
|
|
|
|
) {
|
|
|
|
|
expect(updateVersion).to.equal(oldVersion + increment)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(projectId, (error, newProject) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return callback(error)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(newProject.version).to.equal(updateVersion)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('creating a project from the example template', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId) => {
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
done(err)
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version creating a doc and a file', function () {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
const { updates, version } = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(3)
|
|
|
|
|
for (const update of updates.slice(0, 2)) {
|
|
|
|
|
expect(update.type).to.equal('add-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.be.a('string')
|
2020-05-20 10:14:49 -04:00
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(_.where(updates, { pathname: '/main.tex' }).length).to.equal(1)
|
|
|
|
|
expect(_.where(updates, { pathname: '/references.bib' }).length).to.equal(
|
|
|
|
|
1
|
|
|
|
|
)
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(updates[2].type).to.equal('add-file')
|
|
|
|
|
expect(updates[2].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[2].pathname).to.equal('/universe.jpg')
|
|
|
|
|
expect(updates[2].url).to.be.a('string')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(version).to.equal(3)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('duplicating a project', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let dupProjectId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `/Project/${projectId}/clone`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
|
projectName: 'new.tex',
|
|
|
|
|
},
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to clone project ${res.statusCode}`)
|
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
dupProjectId = body.project_id
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version the docs and files created', function () {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
const { updates, version } = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
dupProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(3)
|
|
|
|
|
for (const update of updates.slice(0, 2)) {
|
|
|
|
|
expect(update.type).to.equal('add-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.be.a('string')
|
2020-05-20 10:14:49 -04:00
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(_.where(updates, { pathname: '/main.tex' }).length).to.equal(1)
|
|
|
|
|
expect(_.where(updates, { pathname: '/references.bib' }).length).to.equal(
|
|
|
|
|
1
|
|
|
|
|
)
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(updates[2].type).to.equal('add-file')
|
|
|
|
|
expect(updates[2].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[2].pathname).to.equal('/universe.jpg')
|
|
|
|
|
expect(updates[2].url).to.be.a('string')
|
2020-05-13 10:15:23 -04:00
|
|
|
|
expect(version).to.equal(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('adding a doc', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, oldVersion
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
|
|
|
|
|
ProjectGetter.getProject(projectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
return done(error)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
oldVersion = project.version
|
|
|
|
|
createExampleDoc(owner, projectId, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version the doc added', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version: newVersion,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('add-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(update.pathname).to.equal('/new.tex')
|
|
|
|
|
expect(update.docLines).to.be.a('string')
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
newVersion,
|
|
|
|
|
1,
|
|
|
|
|
done
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a project', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uploadExampleProject(owner, 'test_project.zip', (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
done()
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version the docs and files created', function () {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
const { updates, version } = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
expect(updates[0].type).to.equal('add-doc')
|
|
|
|
|
expect(updates[0].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[0].pathname).to.equal('/main.tex')
|
|
|
|
|
expect(updates[0].docLines).to.equal('Test')
|
|
|
|
|
expect(updates[1].type).to.equal('add-file')
|
|
|
|
|
expect(updates[1].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[1].pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(updates[1].url).to.be.a('string')
|
2020-04-23 07:51:06 -04:00
|
|
|
|
expect(version).to.equal(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a project with a name', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
const testProjectName = 'wombat'
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uploadExampleProject(
|
|
|
|
|
owner,
|
|
|
|
|
'test_project_with_name.zip',
|
|
|
|
|
(err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should set the project name from the zip contents', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(exampleProjectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(error).not.to.exist
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(project.name).to.equal(testProjectName)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a project with an invalid name', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
const testProjectMatch = /^bad[^\\]+name$/
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uploadExampleProject(
|
|
|
|
|
owner,
|
|
|
|
|
'test_project_with_invalid_name.zip',
|
|
|
|
|
(error, projectId) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
return done(error)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should set the project name from the zip contents', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(exampleProjectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(error).not.to.exist
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(project.name).to.match(testProjectMatch)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading an empty zipfile', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let res
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadExampleProject(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'test_project_empty.zip',
|
|
|
|
|
{ allowBadStatus: true },
|
2020-01-27 08:53:08 -05:00
|
|
|
|
(err, projectId, response) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
res = response
|
|
|
|
|
done()
|
|
|
|
|
}
|
2019-07-02 06:48:57 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should fail with 422 error', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(res.statusCode).to.equal(422)
|
2019-07-02 06:48:57 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a zipfile containing only empty directories', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let res
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadExampleProject(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'test_project_with_empty_folder.zip',
|
|
|
|
|
{ allowBadStatus: true },
|
2020-01-27 08:53:08 -05:00
|
|
|
|
|
|
|
|
|
(err, projectId, response) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
res = response
|
|
|
|
|
done()
|
|
|
|
|
}
|
2019-07-02 06:48:57 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should fail with 422 error', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(res.statusCode).to.equal(422)
|
2019-07-02 06:48:57 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a project with a shared top-level folder', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadExampleProject(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'test_project_with_shared_top_level_folder.zip',
|
2020-01-27 08:53:08 -05:00
|
|
|
|
(err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
done()
|
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should not create the top-level folder', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(exampleProjectId, (error, project) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(error).not.to.exist
|
|
|
|
|
expect(project.rootFolder[0].folders.length).to.equal(0)
|
|
|
|
|
expect(project.rootFolder[0].docs.length).to.equal(2)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a project with backslashes in the path names', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uploadExampleProject(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner,
|
2019-08-07 10:04:04 -04:00
|
|
|
|
'test_project_with_backslash_in_filename.zip',
|
2020-01-27 08:53:08 -05:00
|
|
|
|
(err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
done()
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should treat the backslash as a directory separator', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(exampleProjectId, (error, project) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(error).not.to.exist
|
|
|
|
|
expect(project.rootFolder[0].folders[0].name).to.equal('styles')
|
|
|
|
|
expect(project.rootFolder[0].folders[0].docs[0].name).to.equal('ao.sty')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a project with files in different encodings', function () {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
let updates
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uploadExampleProject(owner, 'charsets/charsets.zip', (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates = MockDocUpdaterApi.getProjectStructureUpdates(projectId)
|
|
|
|
|
.updates
|
2020-01-27 08:53:08 -05:00
|
|
|
|
done()
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should correctly parse windows-1252', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
update => update.pathname === '/test-german-windows-1252.tex'
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.contain(
|
2019-05-29 05:21:06 -04:00
|
|
|
|
'Der schnelle braune Fuchs sprang träge über den Hund.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should correctly parse German utf8', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
update => update.pathname === '/test-german-utf8x.tex'
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.contain(
|
2019-05-29 05:21:06 -04:00
|
|
|
|
'Der schnelle braune Fuchs sprang träge über den Hund.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should correctly parse little-endian utf16', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
update => update.pathname === '/test-greek-utf16-le-bom.tex'
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.contain(
|
2019-05-29 05:21:06 -04:00
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should correctly parse Greek utf8', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
update => update.pathname === '/test-greek-utf8x.tex'
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.contain(
|
2019-05-29 05:21:06 -04:00
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a file', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, oldVersion, rootFolderId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId, folderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
rootFolderId = folderId
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(projectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw error
|
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
|
|
|
|
|
oldVersion = project.version
|
|
|
|
|
|
|
|
|
|
uploadExampleFile(owner, projectId, rootFolderId, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version a newly uploaded file', function (done) {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
const { updates, version } = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('add-file')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.url).to.be.a('string')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
// one file upload
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(exampleProjectId, oldVersion, version, 1, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version a replacement file', function (done) {
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uploadFile(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
rootFolderId,
|
|
|
|
|
'2pixel.png',
|
|
|
|
|
'1pixel.png',
|
|
|
|
|
'image/png',
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(2)
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(updates[0].type).to.equal('rename-file')
|
|
|
|
|
expect(updates[0].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[0].pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(updates[0].newPathname).to.equal('')
|
|
|
|
|
expect(updates[1].type).to.equal('add-file')
|
|
|
|
|
expect(updates[1].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[1].pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(updates[1].url).to.be.a('string')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
// two file uploads
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
2,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('moving entities', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFileId,
|
|
|
|
|
exampleFolderId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId, rootFolderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
createExampleDoc(owner, projectId, (err, docId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleDocId = docId
|
|
|
|
|
uploadExampleFile(owner, projectId, rootFolderId, (err, fileId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleFileId = fileId
|
|
|
|
|
createExampleFolder(owner, projectId, (err, folderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleFolderId = folderId
|
|
|
|
|
|
|
|
|
|
ProjectGetter.getProject(projectId, (error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
oldVersion = project.version
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
done()
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version moving a doc', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
moveItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'doc',
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('rename-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/new.tex')
|
|
|
|
|
|
|
|
|
|
// 2, because it's a delete and then add
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
2,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version moving a file', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
moveItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'file',
|
|
|
|
|
exampleFileId,
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('rename-file')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
|
|
|
|
|
// 2, because it's a delete and then add
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
2,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version moving a folder', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
moveItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'doc',
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
() => {
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
|
|
|
|
|
owner.request.post(
|
|
|
|
|
{
|
|
|
|
|
uri: `project/${exampleProjectId}/folder`,
|
|
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
|
name: 'bar',
|
|
|
|
|
},
|
2020-01-27 08:53:08 -05:00
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
const newFolderId = body._id
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
moveItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'folder',
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
newFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
2021-05-05 09:05:04 -04:00
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('rename-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('/bar/foo/new.tex')
|
|
|
|
|
|
|
|
|
|
// 5, because it's two file moves plus a folder
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
5,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
2020-01-27 08:53:08 -05:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('renaming entities', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId,
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFileId,
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
oldVersion
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId, rootFolderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
createExampleDoc(owner, projectId, (err, docId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleDocId = docId
|
|
|
|
|
uploadExampleFile(owner, projectId, rootFolderId, (err, fileId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleFileId = fileId
|
|
|
|
|
createExampleFolder(owner, projectId, (err, folderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleFolderId = folderId
|
|
|
|
|
moveItem(owner, projectId, 'doc', docId, folderId, () => {
|
|
|
|
|
moveItem(owner, projectId, 'file', fileId, folderId, () => {
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
oldVersion = project.version
|
|
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
2020-01-27 08:53:08 -05:00
|
|
|
|
})
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version renaming a doc', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
renameItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'Doc',
|
|
|
|
|
exampleDocId,
|
|
|
|
|
'wombat.tex',
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('rename-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/wombat.tex')
|
|
|
|
|
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
1,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version renaming a file', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
renameItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'file',
|
|
|
|
|
exampleFileId,
|
|
|
|
|
'potato.png',
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('rename-file')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/potato.png')
|
|
|
|
|
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
1,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version renaming a folder', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
renameItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'folder',
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
'giraffe',
|
|
|
|
|
() => {
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
expect(updates[0].type).to.equal('rename-doc')
|
|
|
|
|
expect(updates[0].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[0].pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(updates[0].newPathname).to.equal('/giraffe/new.tex')
|
|
|
|
|
expect(updates[1].type).to.equal('rename-file')
|
|
|
|
|
expect(updates[1].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[1].pathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
expect(updates[1].newPathname).to.equal('/giraffe/1pixel.png')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
|
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
1,
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('deleting entities', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, oldVersion, exampleFolderId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
createExampleFolder(owner, exampleProjectId, (err, folderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleFolderId = folderId
|
|
|
|
|
createExampleDoc(owner, projectId, (err, docId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
uploadExampleFile(owner, projectId, folderId, (err, fileId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
moveItem(owner, projectId, 'doc', docId, folderId, () => {
|
|
|
|
|
moveItem(owner, projectId, 'file', fileId, folderId, () => {
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
oldVersion = project.version
|
|
|
|
|
done()
|
2019-08-07 10:04:04 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
2020-01-27 08:53:08 -05:00
|
|
|
|
})
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version deleting a folder', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
deleteItem(owner, exampleProjectId, 'folder', exampleFolderId, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
expect(updates[0].type).to.equal('rename-doc')
|
|
|
|
|
expect(updates[0].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[0].pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(updates[0].newPathname).to.equal('')
|
|
|
|
|
expect(updates[1].type).to.equal('rename-file')
|
|
|
|
|
expect(updates[1].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[1].pathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
expect(updates[1].newPathname).to.equal('')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(exampleProjectId, oldVersion, version, 1, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('deleting docs', function () {
|
|
|
|
|
beforeEach(function (done) {
|
2020-02-27 07:46:37 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
this.exampleProjectId = projectId
|
|
|
|
|
createExampleFolder(owner, projectId, (err, folderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
this.exampleFolderId = folderId
|
|
|
|
|
createExampleDoc(owner, projectId, (err, docId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
this.exampleDocId = docId
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-02-27 07:46:37 -05:00
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
this.project0 = project
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should pass the doc name to docstore', function (done) {
|
2021-04-06 05:15:00 -04:00
|
|
|
|
deleteItem(
|
|
|
|
|
owner,
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
'doc',
|
|
|
|
|
this.exampleDocId,
|
|
|
|
|
error => {
|
|
|
|
|
if (error) return done(error)
|
|
|
|
|
expect(
|
|
|
|
|
MockDocStoreApi.getDeletedDocs(this.exampleProjectId)
|
|
|
|
|
).to.deep.equal([{ _id: this.exampleDocId, name: 'new.tex' }])
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('when rootDoc_id matches doc being deleted', function () {
|
|
|
|
|
beforeEach(function (done) {
|
2020-11-03 04:19:05 -05:00
|
|
|
|
Project.updateOne(
|
2020-02-27 07:46:37 -05:00
|
|
|
|
{ _id: this.exampleProjectId },
|
|
|
|
|
{ $set: { rootDoc_id: this.exampleDocId } },
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should clear rootDoc_id', function (done) {
|
2020-02-27 07:46:37 -05:00
|
|
|
|
deleteItem(
|
|
|
|
|
owner,
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
'doc',
|
|
|
|
|
this.exampleDocId,
|
|
|
|
|
() => {
|
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
expect(project.rootDoc_id).to.be.undefined
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('when rootDoc_id does not match doc being deleted', function () {
|
|
|
|
|
beforeEach(function (done) {
|
2020-02-27 07:46:37 -05:00
|
|
|
|
this.exampleRootDocId = new ObjectId()
|
2020-11-03 04:19:05 -05:00
|
|
|
|
Project.updateOne(
|
2020-02-27 07:46:37 -05:00
|
|
|
|
{ _id: this.exampleProjectId },
|
|
|
|
|
{ $set: { rootDoc_id: this.exampleRootDocId } },
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should not clear rootDoc_id', function (done) {
|
2020-02-27 07:46:37 -05:00
|
|
|
|
deleteItem(
|
|
|
|
|
owner,
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
'doc',
|
|
|
|
|
this.exampleDocId,
|
|
|
|
|
() => {
|
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
expect(project.rootDoc_id.toString()).to.equal(
|
|
|
|
|
this.exampleRootDocId.toString()
|
|
|
|
|
)
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('tpds', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let projectName, exampleProjectId, oldVersion, rootFolderId
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
projectName = `tpds-project-${new ObjectId().toString()}`
|
|
|
|
|
owner.createProject(projectName, (error, projectId) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
exampleProjectId = projectId
|
2019-08-06 08:20:41 -04:00
|
|
|
|
mkdirp(Settings.path.dumpFolder, () => {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
ProjectGetter.getProject(exampleProjectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
rootFolderId = project.rootFolder[0]._id.toString()
|
|
|
|
|
oldVersion = project.version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version adding a doc', function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const texFile = fs.createReadStream(
|
|
|
|
|
Path.resolve(Path.join(__dirname, '..', 'files', 'test.tex'))
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
const req = owner.request.post({
|
|
|
|
|
uri: `/user/${owner._id}/update/${projectName}/test.tex`,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
|
sendImmediately: true,
|
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
texFile.on('error', err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw err
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
req.on('error', err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw err
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
req.on('response', res => {
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to upload file ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('add-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(update.pathname).to.equal('/test.tex')
|
|
|
|
|
expect(update.docLines).to.equal('Test')
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(exampleProjectId, oldVersion, version, 1, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
texFile.pipe(req)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version adding a new file', function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const imageFile = fs.createReadStream(
|
|
|
|
|
Path.resolve(Path.join(__dirname, '..', 'files', '1pixel.png'))
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
const req = owner.request.post({
|
|
|
|
|
uri: `/user/${owner._id}/update/${projectName}/1pixel.png`,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
|
sendImmediately: true,
|
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
imageFile.on('error', err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw err
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
req.on('error', err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw err
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
req.on('response', res => {
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to upload file ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('add-file')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.url).to.be.a('string')
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(exampleProjectId, oldVersion, version, 1, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
imageFile.pipe(req)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('when there are files in the project', function () {
|
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uploadExampleFile(owner, exampleProjectId, rootFolderId, () => {
|
|
|
|
|
createExampleDoc(owner, exampleProjectId, () => {
|
|
|
|
|
ProjectGetter.getProject(exampleProjectId, (error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2020-01-27 08:53:08 -05:00
|
|
|
|
oldVersion = project.version
|
|
|
|
|
done()
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version replacing a file', function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const imageFile = fs.createReadStream(
|
|
|
|
|
Path.resolve(Path.join(__dirname, '..', 'files', '2pixel.png'))
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
const req = owner.request.post({
|
|
|
|
|
uri: `/user/${owner._id}/update/${projectName}/1pixel.png`,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
|
sendImmediately: true,
|
|
|
|
|
},
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
imageFile.on('error', err => {
|
|
|
|
|
throw err
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
req.on('error', err => {
|
|
|
|
|
throw err
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
req.on('response', res => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
throw new Error(`failed to upload file ${res.statusCode}`)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(updates.length).to.equal(2)
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(updates[0].type).to.equal('rename-file')
|
|
|
|
|
expect(updates[0].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[0].pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(updates[0].newPathname).to.equal('')
|
|
|
|
|
expect(updates[1].type).to.equal('add-file')
|
|
|
|
|
expect(updates[1].userId).to.equal(owner._id)
|
|
|
|
|
expect(updates[1].pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(updates[1].url).to.be.a('string')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
1,
|
|
|
|
|
done
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
imageFile.pipe(req)
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should version deleting a doc', function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner.request.delete(
|
2019-05-29 05:21:06 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `/user/${owner._id}/update/${projectName}/new.tex`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
|
sendImmediately: true,
|
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
|
},
|
2019-08-06 08:20:41 -04:00
|
|
|
|
(error, res) => {
|
|
|
|
|
if (error) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
throw new Error(`failed to delete doc ${res.statusCode}`)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2021-04-27 03:52:58 -04:00
|
|
|
|
version,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(exampleProjectId)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('rename-doc')
|
2020-01-27 08:53:08 -05:00
|
|
|
|
expect(update.userId).to.equal(owner._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.pathname).to.equal('/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('')
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
verifyVersionIncremented(
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
version,
|
|
|
|
|
1,
|
|
|
|
|
done
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('uploading a document', function () {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, rootFolderId
|
2021-04-14 09:17:21 -04:00
|
|
|
|
beforeEach(function (done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId, folderId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
|
|
|
|
rootFolderId = folderId
|
2021-02-25 07:22:24 -05:00
|
|
|
|
MockDocUpdaterApi.reset()
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
describe('with an unusual character set', function () {
|
|
|
|
|
it('should correctly handle utf16-le data', function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadFile(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
rootFolderId,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'charsets/test-greek-utf16-le-bom.tex',
|
|
|
|
|
'test-greek-utf16-le-bom.tex',
|
|
|
|
|
'text/x-tex',
|
|
|
|
|
() => {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
const { updates } = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('add-doc')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(update.pathname).to.equal('/test-greek-utf16-le-bom.tex')
|
|
|
|
|
expect(update.docLines).to.contain(
|
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
|
it('should correctly handle windows1252/iso-8859-1/latin1 data', function (done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadFile(
|
2020-01-27 08:53:08 -05:00
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
rootFolderId,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'charsets/test-german-windows-1252.tex',
|
|
|
|
|
'test-german-windows-1252.tex',
|
|
|
|
|
'text/x-tex',
|
|
|
|
|
() => {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
const { updates } = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = updates[0]
|
2020-05-20 10:14:49 -04:00
|
|
|
|
expect(update.type).to.equal('add-doc')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(update.pathname).to.equal('/test-german-windows-1252.tex')
|
|
|
|
|
expect(update.docLines).to.contain(
|
|
|
|
|
'Der schnelle braune Fuchs sprang träge über den Hund.'
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|