2019-05-29 05:21:06 -04:00
|
|
|
|
const { expect } = require('chai')
|
|
|
|
|
const mkdirp = require('mkdirp')
|
|
|
|
|
const { ObjectId } = require('mongojs')
|
|
|
|
|
const Path = require('path')
|
|
|
|
|
const fs = require('fs')
|
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
|
const _ = require('underscore')
|
|
|
|
|
|
|
|
|
|
const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
|
|
|
|
|
|
|
|
|
|
const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
require('./helpers/MockFileStoreApi')
|
|
|
|
|
require('./helpers/MockProjectHistoryApi')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const User = require('./helpers/User')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('ProjectStructureChanges', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
this.owner = new User()
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.owner.login(done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function createExampleProject(test, callback) {
|
|
|
|
|
test.owner.createProject(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'example-project',
|
|
|
|
|
{ template: 'example' },
|
|
|
|
|
(error, projectId) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.exampleProjectId = projectId
|
2019-08-06 08:20:41 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
ProjectGetter.getProject(test.exampleProjectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.rootFolderId = project.rootFolder[0]._id.toString()
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function createExampleDoc(test, callback) {
|
|
|
|
|
ProjectGetter.getProject(test.exampleProjectId, (error, project) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uri: `project/${test.exampleProjectId}/doc`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
name: 'new.tex',
|
|
|
|
|
parent_folder_id: project.rootFolder[0]._id
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw error
|
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to add doc ${res.statusCode}`)
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.exampleDocId = body._id
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function createExampleFolder(test, callback) {
|
|
|
|
|
test.owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uri: `project/${test.exampleProjectId}/folder`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
name: 'foo'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to add doc ${res.statusCode}`)
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.exampleFolderId = body._id
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function uploadFile(test, file, name, contentType, callback) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const imageFile = fs.createReadStream(
|
|
|
|
|
Path.resolve(Path.join(__dirname, '..', 'files', file))
|
|
|
|
|
)
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uri: `project/${test.exampleProjectId}/upload`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
qs: {
|
2019-08-07 10:04:04 -04:00
|
|
|
|
folder_id: test.rootFolderId
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
formData: {
|
|
|
|
|
qqfile: {
|
|
|
|
|
value: imageFile,
|
|
|
|
|
options: {
|
|
|
|
|
filename: name,
|
|
|
|
|
contentType: contentType
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to upload file ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.exampleFileId = JSON.parse(body).entity_id
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function uploadExampleFile(test, callback) {
|
|
|
|
|
uploadFile(test, '1pixel.png', '1pixel.png', 'image/png', callback)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function uploadExampleProject(test, 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))
|
|
|
|
|
)
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
|
|
|
|
uri: 'project/new/upload',
|
|
|
|
|
formData: {
|
|
|
|
|
qqfile: zipFile
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
!options.allowBadStatus &&
|
|
|
|
|
(res.statusCode < 200 || res.statusCode >= 300)
|
|
|
|
|
) {
|
|
|
|
|
throw new Error(`failed to upload project ${res.statusCode}`)
|
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
test.uploadedProjectId = JSON.parse(body).project_id
|
|
|
|
|
test.res = res
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function moveItem(test, type, itemId, folderId, callback) {
|
|
|
|
|
test.owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uri: `project/${test.exampleProjectId}/${type}/${itemId}/move`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
folder_id: folderId
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to move ${type} ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function renameItem(test, type, itemId, name, callback) {
|
|
|
|
|
test.owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uri: `project/${test.exampleProjectId}/${type}/${itemId}/rename`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
name: name
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to rename ${type} ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function deleteItem(test, type, itemId, callback) {
|
|
|
|
|
test.owner.request.delete(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uri: `project/${test.exampleProjectId}/${type}/${itemId}`
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
(error, res) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to delete folder ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
function verifyVersionIncremented(test, updateVersion, increment, callback) {
|
|
|
|
|
expect(updateVersion).to.equal(test.project0.version + increment)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
ProjectGetter.getProject(test.exampleProjectId, (error, newProject) => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
expect(newProject.version).to.equal(test.project0.version + increment)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
callback()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('creating a project from the example template', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
2019-08-07 10:04:04 -04:00
|
|
|
|
createExampleProject(this, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version creating a doc', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
_.each(updates, update => {
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.be.a('string')
|
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
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(version).to.equal(3)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version creating a file', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/universe.jpg')
|
|
|
|
|
expect(update.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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('duplicating a project', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
2019-08-07 10:04:04 -04:00
|
|
|
|
createExampleProject(this, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.owner.request.post(
|
|
|
|
|
{
|
|
|
|
|
uri: `/Project/${this.exampleProjectId}/clone`,
|
|
|
|
|
json: {
|
|
|
|
|
projectName: 'new.tex'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
|
throw new Error(`failed to clone project ${res.statusCode}`)
|
|
|
|
|
}
|
|
|
|
|
this.dupProjectId = body.project_id
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version the docs created', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.dupProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
_.each(updates, update => {
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(update.docLines).to.be.a('string')
|
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
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(version).to.equal(3)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version the files created', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.dupProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/universe.jpg')
|
|
|
|
|
expect(update.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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('adding a doc', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
createExampleProject(this, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
ProjectGetter.getProject(this.exampleProjectId, (error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.project0 = project
|
2019-08-07 10:04:04 -04:00
|
|
|
|
createExampleDoc(this, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version the doc added', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/new.tex')
|
|
|
|
|
expect(update.docLines).to.be.a('string')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
uploadExampleProject(this, 'test_project.zip', done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version the docs created', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.uploadedProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/main.tex')
|
|
|
|
|
expect(update.docLines).to.equal('Test')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(version).to.equal(2)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version the files created', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.uploadedProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.url).to.be.a('string')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(version).to.equal(2)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with a name', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.testProjectName = 'wombat'
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uploadExampleProject(this, 'test_project_with_name.zip', done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should set the project name from the zip contents', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
ProjectGetter.getProject(this.uploadedProjectId, (error, project) => {
|
|
|
|
|
expect(error).not.to.exist
|
|
|
|
|
expect(project.name).to.equal(this.testProjectName)
|
|
|
|
|
done()
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with an invalid name', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.testProjectMatch = /^bad[^\\]+name$/
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uploadExampleProject(this, 'test_project_with_invalid_name.zip', done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should set the project name from the zip contents', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
ProjectGetter.getProject(this.uploadedProjectId, (error, project) => {
|
|
|
|
|
expect(error).not.to.exist
|
|
|
|
|
expect(project.name).to.match(this.testProjectMatch)
|
|
|
|
|
done()
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading an empty zipfile', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadExampleProject(
|
2019-08-07 10:04:04 -04:00
|
|
|
|
this,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'test_project_empty.zip',
|
|
|
|
|
{ allowBadStatus: true },
|
|
|
|
|
done
|
2019-07-02 06:48:57 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should fail with 422 error', function() {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(this.res.statusCode).to.equal(422)
|
2019-07-02 06:48:57 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a zipfile containing only empty directories', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadExampleProject(
|
2019-08-07 10:04:04 -04:00
|
|
|
|
this,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'test_project_with_empty_folder.zip',
|
|
|
|
|
{ allowBadStatus: true },
|
|
|
|
|
done
|
2019-07-02 06:48:57 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should fail with 422 error', function() {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(this.res.statusCode).to.equal(422)
|
2019-07-02 06:48:57 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with a shared top-level folder', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadExampleProject(
|
2019-08-07 10:04:04 -04:00
|
|
|
|
this,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'test_project_with_shared_top_level_folder.zip',
|
|
|
|
|
done
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should not create the top-level folder', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
ProjectGetter.getProject(this.uploadedProjectId, (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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with backslashes in the path names', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
uploadExampleProject(
|
|
|
|
|
this,
|
|
|
|
|
'test_project_with_backslash_in_filename.zip',
|
|
|
|
|
done
|
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should treat the backslash as a directory separator', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
ProjectGetter.getProject(this.uploadedProjectId, (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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with files in different encodings', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
uploadExampleProject(this, 'charsets/charsets.zip', done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should correctly parse windows-1252', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.uploadedProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
|
|
|
|
updates,
|
|
|
|
|
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.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should correctly parse German utf8', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.uploadedProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
|
|
|
|
updates,
|
|
|
|
|
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.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should correctly parse little-endian utf16', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.uploadedProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
|
|
|
|
updates,
|
|
|
|
|
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
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should correctly parse Greek utf8', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.uploadedProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = _.find(
|
|
|
|
|
updates,
|
|
|
|
|
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
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a file', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
createExampleProject(this, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
ProjectGetter.getProject(this.exampleProjectId, (error, project) => {
|
|
|
|
|
if (error) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
throw error
|
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.project0 = project
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uploadExampleFile(this, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version a newly uploaded file', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
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
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version a replacement file', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
uploadFile(this, '2pixel.png', '1pixel.png', 'image/png', () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
let update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
update = updates[1]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
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
|
|
|
|
// two file uploads
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 2, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('moving entities', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
createExampleProject(this, () => {
|
|
|
|
|
createExampleDoc(this, () => {
|
|
|
|
|
uploadExampleFile(this, () => {
|
|
|
|
|
createExampleFolder(this, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
this.project0 = project
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version moving a doc', function(done) {
|
|
|
|
|
moveItem(this, 'doc', this.exampleDocId, this.exampleFolderId, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/new.tex')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
// 2, because it's a delete and then add
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 2, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version moving a file', function(done) {
|
|
|
|
|
moveItem(this, 'file', this.exampleFileId, this.exampleFolderId, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/1pixel.png')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
// 2, because it's a delete and then add
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 2, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version moving a folder', function(done) {
|
|
|
|
|
moveItem(this, 'doc', this.exampleDocId, this.exampleFolderId, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.owner.request.post(
|
|
|
|
|
{
|
|
|
|
|
uri: `project/${this.exampleProjectId}/folder`,
|
|
|
|
|
json: {
|
|
|
|
|
name: 'bar'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res, body) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
const newFolderId = body._id
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
moveItem(this, 'folder', this.exampleFolderId, newFolderId, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.exampleProjectId
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
let update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('/bar/foo/new.tex')
|
2019-08-06 08:20:41 -04:00
|
|
|
|
|
|
|
|
|
// 5, because it's two file moves plus a folder
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 5, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('renaming entities', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
createExampleProject(this, () => {
|
|
|
|
|
createExampleDoc(this, () => {
|
|
|
|
|
uploadExampleFile(this, () => {
|
|
|
|
|
createExampleFolder(this, () => {
|
|
|
|
|
moveItem(
|
|
|
|
|
this,
|
|
|
|
|
'doc',
|
|
|
|
|
this.exampleDocId,
|
|
|
|
|
this.exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
moveItem(
|
|
|
|
|
this,
|
|
|
|
|
'file',
|
|
|
|
|
this.exampleFileId,
|
|
|
|
|
this.exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
this.project0 = project
|
|
|
|
|
done()
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version renaming a doc', function(done) {
|
|
|
|
|
renameItem(this, 'Doc', this.exampleDocId, 'wombat.tex', () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/wombat.tex')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version renaming a file', function(done) {
|
|
|
|
|
renameItem(this, 'file', this.exampleFileId, 'potato.png', () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
expect(update.newPathname).to.equal('/foo/potato.png')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version renaming a folder', function(done) {
|
|
|
|
|
renameItem(this, 'folder', this.exampleFolderId, 'giraffe', () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates,
|
|
|
|
|
fileUpdates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(docUpdates.length).to.equal(1)
|
|
|
|
|
const docUpdate = docUpdates[0]
|
|
|
|
|
expect(docUpdate.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(docUpdate.pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(docUpdate.newPathname).to.equal('/giraffe/new.tex')
|
|
|
|
|
|
|
|
|
|
expect(fileUpdates.length).to.equal(1)
|
|
|
|
|
const fileUpdate = fileUpdates[0]
|
|
|
|
|
expect(fileUpdate.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(fileUpdate.pathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
expect(fileUpdate.newPathname).to.equal('/giraffe/1pixel.png')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('deleting entities', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
createExampleProject(this, () => {
|
|
|
|
|
createExampleFolder(this, () => {
|
|
|
|
|
createExampleDoc(this, () => {
|
|
|
|
|
uploadExampleFile(this, () => {
|
|
|
|
|
moveItem(
|
|
|
|
|
this,
|
|
|
|
|
'doc',
|
|
|
|
|
this.exampleDocId,
|
|
|
|
|
this.exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
moveItem(
|
|
|
|
|
this,
|
|
|
|
|
'file',
|
|
|
|
|
this.exampleFileId,
|
|
|
|
|
this.exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
this.project0 = project
|
|
|
|
|
done()
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
2019-08-07 10:04:04 -04:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version deleting a folder', function(done) {
|
|
|
|
|
deleteItem(this, 'folder', this.exampleFolderId, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates,
|
|
|
|
|
fileUpdates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
|
|
|
|
expect(docUpdates.length).to.equal(1)
|
|
|
|
|
const docUpdate = docUpdates[0]
|
|
|
|
|
expect(docUpdate.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(docUpdate.pathname).to.equal('/foo/new.tex')
|
|
|
|
|
expect(docUpdate.newPathname).to.equal('')
|
|
|
|
|
|
|
|
|
|
expect(fileUpdates.length).to.equal(1)
|
|
|
|
|
const fileUpdate = fileUpdates[0]
|
|
|
|
|
expect(fileUpdate.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(fileUpdate.pathname).to.equal('/foo/1pixel.png')
|
|
|
|
|
expect(fileUpdate.newPathname).to.equal('')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('tpds', function() {
|
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.tpdsProjectName = `tpds-project-${new ObjectId().toString()}`
|
|
|
|
|
this.owner.createProject(this.tpdsProjectName, (error, projectId) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.exampleProjectId = projectId
|
|
|
|
|
mkdirp(Settings.path.dumpFolder, () => {
|
|
|
|
|
ProjectGetter.getProject(this.exampleProjectId, (error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
this.rootFolderId = project.rootFolder[0]._id.toString()
|
|
|
|
|
this.project0 = project
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const req = this.owner.request.post({
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uri: `/user/${this.owner._id}/update/${this.tpdsProjectName}/test.tex`,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
|
|
|
|
sendImmediately: true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
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 {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/test.tex')
|
|
|
|
|
expect(update.docLines).to.equal('Test')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, 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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const req = this.owner.request.post({
|
|
|
|
|
uri: `/user/${this.owner._id}/update/${
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.tpdsProjectName
|
2019-05-29 05:21:06 -04:00
|
|
|
|
}/1pixel.png`,
|
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
|
|
|
|
sendImmediately: true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
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 {
|
|
|
|
|
fileUpdates: updates,
|
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(this.exampleProjectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.url).to.be.a('string')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, 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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('when there are files in the project', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
uploadExampleFile(this, () => {
|
|
|
|
|
createExampleDoc(this, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
this.project0 = project
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
)
|
|
|
|
|
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const req = this.owner.request.post({
|
2019-05-29 05:21:06 -04:00
|
|
|
|
uri: `/user/${this.owner._id}/update/${
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.tpdsProjectName
|
|
|
|
|
}/1pixel.png`,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
|
|
|
|
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 {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
fileUpdates: updates,
|
2019-05-29 05:21:06 -04:00
|
|
|
|
version
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
this.exampleProjectId
|
2019-05-29 05:21:06 -04:00
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
expect(updates.length).to.equal(2)
|
|
|
|
|
let update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
// expect(update.url).to.be.a('string');
|
|
|
|
|
update = updates[1]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/1pixel.png')
|
|
|
|
|
expect(update.url).to.be.a('string')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, 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
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version deleting a doc', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
this.owner.request.delete(
|
2019-05-29 05:21:06 -04:00
|
|
|
|
{
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uri: `/user/${this.owner._id}/update/${
|
|
|
|
|
this.tpdsProjectName
|
|
|
|
|
}/new.tex`,
|
|
|
|
|
auth: {
|
|
|
|
|
user: _.keys(Settings.httpAuthUsers)[0],
|
|
|
|
|
pass: _.values(Settings.httpAuthUsers)[0],
|
|
|
|
|
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 {
|
|
|
|
|
docUpdates: updates,
|
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
this.exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
const update = updates[0]
|
|
|
|
|
expect(update.userId).to.equal(this.owner._id)
|
|
|
|
|
expect(update.pathname).to.equal('/new.tex')
|
|
|
|
|
expect(update.newPathname).to.equal('')
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
verifyVersionIncremented(this, version, 1, done)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a document', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
createExampleProject(this, () => {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
2019-08-07 10:04:04 -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(
|
2019-08-07 10:04:04 -04:00
|
|
|
|
this,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'charsets/test-greek-utf16-le-bom.tex',
|
|
|
|
|
'test-greek-utf16-le-bom.tex',
|
|
|
|
|
'text/x-tex',
|
|
|
|
|
() => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
this.exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = updates[0]
|
|
|
|
|
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
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should correctly handle windows1252/iso-8859-1/latin1 data', function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
uploadFile(
|
2019-08-07 10:04:04 -04:00
|
|
|
|
this,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
'charsets/test-german-windows-1252.tex',
|
|
|
|
|
'test-german-windows-1252.tex',
|
|
|
|
|
'text/x-tex',
|
|
|
|
|
() => {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const {
|
|
|
|
|
docUpdates: updates
|
2019-08-06 08:20:41 -04:00
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
this.exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
const update = updates[0]
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|