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 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() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let owner
|
|
|
|
|
|
2019-08-07 10:04:04 -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',
|
|
|
|
|
parent_folder_id: project.rootFolder[0]._id
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(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: {
|
|
|
|
|
name: 'foo'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(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
|
|
|
|
|
) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
const imageFile = fs.createReadStream(
|
|
|
|
|
Path.resolve(Path.join(__dirname, '..', 'files', file))
|
|
|
|
|
)
|
|
|
|
|
|
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}/upload`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
qs: {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
folder_id: folderId
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
formData: {
|
|
|
|
|
qqfile: {
|
|
|
|
|
value: imageFile,
|
|
|
|
|
options: {
|
|
|
|
|
filename: name,
|
|
|
|
|
contentType: contentType
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(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 upload file ${res.statusCode}`))
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
callback(null, JSON.parse(body).entity_id)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function uploadExampleFile(owner, projectId, folderId, callback) {
|
|
|
|
|
uploadFile(
|
|
|
|
|
owner,
|
|
|
|
|
projectId,
|
|
|
|
|
folderId,
|
|
|
|
|
'1pixel.png',
|
|
|
|
|
'1pixel.png',
|
|
|
|
|
'image/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: {
|
|
|
|
|
qqfile: zipFile
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(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) {
|
|
|
|
|
owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `project/${projectId}/${type}/${itemId}/move`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
folder_id: folderId
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res) => {
|
|
|
|
|
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 move ${type} ${res.statusCode}`))
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function renameItem(owner, projectId, type, itemId, name, callback) {
|
|
|
|
|
owner.request.post(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `project/${projectId}/${type}/${itemId}/rename`,
|
2019-08-06 08:20:41 -04:00
|
|
|
|
json: {
|
|
|
|
|
name: name
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(error, res) => {
|
|
|
|
|
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 rename ${type} ${res.statusCode}`)
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:53:08 -05:00
|
|
|
|
function deleteItem(owner, projectId, type, itemId, callback) {
|
|
|
|
|
owner.request.delete(
|
2019-08-06 08:20:41 -04:00
|
|
|
|
{
|
2020-01-27 08:53:08 -05:00
|
|
|
|
uri: `project/${projectId}/${type}/${itemId}`
|
2019-08-06 08:20:41 -04:00
|
|
|
|
},
|
|
|
|
|
(error, res) => {
|
|
|
|
|
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 delete folder ${res.statusCode}`)
|
|
|
|
|
)
|
2019-08-06 08:20:41 -04:00
|
|
|
|
}
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('creating a project from the example template', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
beforeEach(function(done) {
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
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
|
|
|
|
|
2020-05-20 10:14:49 -04:00
|
|
|
|
it('should version creating a doc and a file', function() {
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('duplicating a project', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let dupProjectId
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
beforeEach(function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
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: {
|
|
|
|
|
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}`)
|
|
|
|
|
}
|
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
|
|
|
|
})
|
|
|
|
|
|
2020-05-20 10:14:49 -04:00
|
|
|
|
it('should version the docs and files created', function() {
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('adding a doc', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, oldVersion
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
beforeEach(function(done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
createExampleProject(owner, (err, projectId) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return done(err)
|
|
|
|
|
}
|
|
|
|
|
exampleProjectId = projectId
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
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 {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version: newVersion
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
|
2020-05-20 10:14:49 -04:00
|
|
|
|
it('should version the docs and files created', function() {
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with a name', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
const testProjectName = 'wombat'
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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$/
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading an empty zipfile', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let res
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a zipfile containing only empty directories', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let res
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with a shared top-level folder', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with backslashes in the path names', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a project with files in different encodings', function() {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
let updates
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
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 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
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
'Η γρήγορη καστανή αλεπού πήδηξε χαλαρά πάνω από το σκυλί.'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a file', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, oldVersion, rootFolderId
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
2019-08-06 08:20:41 -04:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
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
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
})
|
|
|
|
|
|
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
|
|
|
|
|
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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('moving entities', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId,
|
|
|
|
|
oldVersion,
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFileId,
|
|
|
|
|
exampleFolderId
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
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 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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
it('should version moving a folder', function(done) {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
moveItem(
|
|
|
|
|
owner,
|
|
|
|
|
exampleProjectId,
|
|
|
|
|
'doc',
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
() => {
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
|
|
|
|
|
owner.request.post(
|
|
|
|
|
{
|
|
|
|
|
uri: `project/${exampleProjectId}/folder`,
|
|
|
|
|
json: {
|
|
|
|
|
name: 'bar'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = MockDocUpdaterApi.getProjectStructureUpdates(
|
|
|
|
|
exampleProjectId
|
|
|
|
|
)
|
|
|
|
|
expect(updates.length).to.equal(1)
|
|
|
|
|
let 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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('renaming entities', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId,
|
|
|
|
|
exampleDocId,
|
|
|
|
|
exampleFileId,
|
|
|
|
|
exampleFolderId,
|
|
|
|
|
oldVersion
|
|
|
|
|
|
2019-08-07 10:04:04 -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, () => {
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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,
|
2020-01-27 08:53:08 -05:00
|
|
|
|
version
|
|
|
|
|
} = 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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('deleting entities', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, oldVersion, exampleFolderId
|
|
|
|
|
|
2019-08-07 10:04:04 -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, () => {
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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,
|
2019-08-06 08:20:41 -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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2020-02-27 07:46:37 -05:00
|
|
|
|
describe('deleting docs', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
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
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
ProjectGetter.getProject(
|
|
|
|
|
this.exampleProjectId,
|
|
|
|
|
(error, project) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error
|
|
|
|
|
}
|
|
|
|
|
this.project0 = project
|
|
|
|
|
done()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('when rootDoc_id matches doc being deleted', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
Project.update(
|
|
|
|
|
{ _id: this.exampleProjectId },
|
|
|
|
|
{ $set: { rootDoc_id: this.exampleDocId } },
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should clear rootDoc_id', function(done) {
|
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('when rootDoc_id does not match doc being deleted', function() {
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
|
this.exampleRootDocId = new ObjectId()
|
|
|
|
|
Project.update(
|
|
|
|
|
{ _id: this.exampleProjectId },
|
|
|
|
|
{ $set: { rootDoc_id: this.exampleRootDocId } },
|
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should not clear rootDoc_id', function(done) {
|
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('tpds', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let projectName, exampleProjectId, oldVersion, rootFolderId
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
|
}
|
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
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
|
|
|
|
})
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
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],
|
|
|
|
|
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 {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2019-05-29 05:21:06 -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
|
|
|
|
})
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
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],
|
|
|
|
|
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 {
|
2020-05-20 10:14:49 -04:00
|
|
|
|
updates,
|
2019-05-29 05:21:06 -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
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -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
|
|
|
|
}
|
2020-01-27 08:53:08 -05:00
|
|
|
|
MockDocUpdaterApi.clearProjectStructureUpdates()
|
|
|
|
|
oldVersion = project.version
|
|
|
|
|
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 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],
|
|
|
|
|
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,
|
2019-05-29 05:21:06 -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
|
|
|
|
|
2019-08-07 10:04:04 -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],
|
|
|
|
|
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,
|
2019-08-06 08:20:41 -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
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
|
describe('uploading a document', function() {
|
2020-01-27 08:53:08 -05:00
|
|
|
|
let exampleProjectId, rootFolderId
|
2019-08-07 10:04:04 -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
|
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(
|
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
|
|
|
|
|
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(
|
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
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|