2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
2020-12-15 05:23:54 -05:00
|
|
|
node/handle-callback-err,
|
2019-05-29 05:21:06 -04:00
|
|
|
max-len,
|
|
|
|
mocha/no-identical-title,
|
|
|
|
no-path-concat,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const async = require('async')
|
|
|
|
const { expect } = require('chai')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const mkdirp = require('mkdirp')
|
|
|
|
const Path = require('path')
|
|
|
|
const fs = require('fs')
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2019-05-29 05:21:06 -04:00
|
|
|
const _ = require('underscore')
|
|
|
|
|
|
|
|
const ProjectGetter = require('../../../app/src/Features/Project/ProjectGetter.js')
|
|
|
|
|
|
|
|
const request = require('./helpers/request')
|
|
|
|
const User = require('./helpers/User')
|
|
|
|
|
2021-02-25 07:22:24 -05:00
|
|
|
const MockDocstoreApiClass = require('./mocks/MockDocstoreApi')
|
|
|
|
const MockFilestoreApiClass = require('./mocks/MockFilestoreApi')
|
|
|
|
|
|
|
|
let MockDocstoreApi, MockFilestoreApi
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
before(function () {
|
2021-02-25 07:22:24 -05:00
|
|
|
MockDocstoreApi = MockDocstoreApiClass.instance()
|
|
|
|
MockFilestoreApi = MockFilestoreApiClass.instance()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('ProjectDuplicateNames', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.owner = new User()
|
|
|
|
this.owner.login(done)
|
|
|
|
this.project = {}
|
|
|
|
return (this.callback = sinon.stub())
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('creating a project from the example template', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.createProject(
|
|
|
|
'example-project',
|
|
|
|
{ template: 'example' },
|
|
|
|
(error, project_id) => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
this.example_project_id = project_id
|
|
|
|
return this.owner.getProject(project_id, (error, project) => {
|
|
|
|
this.project = project
|
|
|
|
this.mainTexDoc = _.find(
|
|
|
|
project.rootFolder[0].docs,
|
|
|
|
doc => doc.name === 'main.tex'
|
|
|
|
)
|
|
|
|
this.refBibDoc = _.find(
|
|
|
|
project.rootFolder[0].docs,
|
2021-08-19 05:37:25 -04:00
|
|
|
doc => doc.name === 'sample.bib'
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
this.imageFile = _.find(
|
|
|
|
project.rootFolder[0].fileRefs,
|
2021-08-19 05:37:25 -04:00
|
|
|
file => file.name === 'frog.jpg'
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
this.rootFolderId = project.rootFolder[0]._id.toString()
|
|
|
|
// create a folder called 'testfolder'
|
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
|
|
|
name: 'testfolder',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.testFolderId = body._id
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should create a project', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(this.project.rootFolder[0].docs.length).to.equal(2)
|
|
|
|
return expect(this.project.rootFolder[0].fileRefs.length).to.equal(1)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should create two docs in the docstore', function () {
|
2021-02-25 07:22:24 -05:00
|
|
|
const docs = MockDocstoreApi.docs[this.example_project_id]
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(Object.keys(docs).length).to.equal(2)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should create one file in the filestore', function () {
|
2021-02-25 07:22:24 -05:00
|
|
|
const files = MockFilestoreApi.files[this.example_project_id]
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(Object.keys(files).length).to.equal(1)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing doc', function () {
|
|
|
|
describe('trying to add a doc with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/doc`,
|
|
|
|
json: {
|
|
|
|
name: 'main.tex',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to add a folder with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
|
|
|
name: 'main.tex',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to add a folder with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
|
|
|
name: 'main.tex',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing file', function () {
|
|
|
|
describe('trying to add a doc with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/doc`,
|
|
|
|
json: {
|
2021-08-19 05:37:25 -04:00
|
|
|
name: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to add a folder with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
2021-08-19 05:37:25 -04:00
|
|
|
name: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to upload a file with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/upload`,
|
|
|
|
json: true,
|
|
|
|
qs: {
|
|
|
|
folder_id: this.rootFolderId,
|
2021-08-19 05:37:25 -04:00
|
|
|
qqfilename: 'frog.jpg',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
formData: {
|
|
|
|
qqfile: {
|
|
|
|
value: fs.createReadStream(
|
|
|
|
Path.resolve(__dirname + '/../files/1pixel.png')
|
|
|
|
),
|
|
|
|
options: {
|
2021-08-19 05:37:25 -04:00
|
|
|
filename: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
contentType: 'image/jpeg',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.body = body
|
|
|
|
// update the image id because we have replaced the file
|
|
|
|
this.imageFile._id = this.body.entity_id
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should succeed (overwriting the file)', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.body.success).to.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// at this point the @imageFile._id has changed
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing folder', function () {
|
|
|
|
describe('trying to add a doc with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/doc`,
|
|
|
|
json: {
|
|
|
|
name: 'testfolder',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to add a folder with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
|
|
|
name: 'testfolder',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to upload a file with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/upload`,
|
|
|
|
json: true,
|
|
|
|
qs: {
|
|
|
|
folder_id: this.rootFolderId,
|
2021-08-19 05:37:25 -04:00
|
|
|
qqfilename: 'frog.jpg',
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
formData: {
|
|
|
|
qqfile: {
|
|
|
|
value: fs.createReadStream(
|
|
|
|
Path.resolve(__dirname + '/../files/1pixel.png')
|
|
|
|
),
|
|
|
|
options: {
|
|
|
|
filename: 'testfolder',
|
2021-04-27 03:52:58 -04:00
|
|
|
contentType: 'image/jpeg',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.body = body
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with failure status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.body.success).to.equal(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing doc', function () {
|
|
|
|
describe('trying to rename a doc to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/doc/${this.refBibDoc._id}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'main.tex',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to rename a folder to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'main.tex',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to rename a file to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'main.tex',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with failure status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing file', function () {
|
|
|
|
describe('trying to rename a doc to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/doc/${this.refBibDoc._id}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-08-19 05:37:25 -04:00
|
|
|
name: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to rename a folder to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-08-19 05:37:25 -04:00
|
|
|
name: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to rename a file to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-08-19 05:37:25 -04:00
|
|
|
name: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with failure status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing folder', function () {
|
|
|
|
describe('trying to rename a doc to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/doc/${this.refBibDoc._id}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'testfolder',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to rename a folder to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'testfolder',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to rename a file to the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/rename`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'testfolder',
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with failure status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('for an existing folder with a file with the same name', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/doc`,
|
|
|
|
json: {
|
|
|
|
name: 'main.tex',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.testFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/doc`,
|
|
|
|
json: {
|
2021-08-19 05:37:25 -04:00
|
|
|
name: 'frog.jpg',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.testFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
|
|
|
name: 'otherFolder',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.testFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.subFolderId = body._id
|
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
|
|
|
uri: `/project/${this.example_project_id}/folder`,
|
|
|
|
json: {
|
|
|
|
name: 'otherFolder',
|
2021-04-27 03:52:58 -04:00
|
|
|
parent_folder_id: this.rootFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.otherFolderId = body._id
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to move a doc into the folder', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/doc/${this.mainTexDoc._id}/move`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
folder_id: this.testFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to move a file into the folder', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/file/${this.imageFile._id}/move`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
folder_id: this.testFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to move a folder into the folder', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/folder/${this.otherFolderId}/move`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
folder_id: this.testFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('trying to move a folder into a subfolder of itself', function () {
|
|
|
|
beforeEach(function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.owner.request.post(
|
|
|
|
{
|
2020-12-15 05:23:54 -05:00
|
|
|
uri: `/project/${this.example_project_id}/folder/${this.testFolderId}/move`,
|
2019-05-29 05:21:06 -04:00
|
|
|
json: {
|
2021-04-27 03:52:58 -04:00
|
|
|
folder_id: this.subFolderId,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
(err, res, body) => {
|
|
|
|
this.res = res
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with 400 error status', function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
return expect(this.res.statusCode).to.equal(400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|