Merge pull request #4761 from overleaf/em-peek-doc
Do not unarchive docs when resyncing project history GitOrigin-RevId: c7df75789c01e6c85b464a9b94b14654d8568407
This commit is contained in:
@@ -1,14 +1,3 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
no-return-assign,
|
||||
*/
|
||||
// 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
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/src/Features/Docstore/DocstoreManager'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
@@ -37,7 +26,7 @@ describe('DocstoreManager', function () {
|
||||
|
||||
this.project_id = 'project-id-123'
|
||||
this.doc_id = 'doc-id-123'
|
||||
return (this.callback = sinon.stub())
|
||||
this.callback = sinon.stub()
|
||||
})
|
||||
|
||||
describe('deleteDoc', function () {
|
||||
@@ -54,7 +43,7 @@ describe('DocstoreManager', function () {
|
||||
this.request.patch = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 }, '')
|
||||
return this.DocstoreManager.deleteDoc(
|
||||
this.DocstoreManager.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
'wombat.tex',
|
||||
@@ -64,7 +53,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should delete the doc in the docstore api', function () {
|
||||
return this.request.patch
|
||||
this.request.patch
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
||||
json: { deleted: true, deletedAt: new Date(), name: 'wombat.tex' },
|
||||
@@ -74,7 +63,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should call the callback without an error', function () {
|
||||
return this.callback.calledWith(null).should.equal(true)
|
||||
this.callback.calledWith(null).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -83,7 +72,7 @@ describe('DocstoreManager', function () {
|
||||
this.request.patch = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.DocstoreManager.deleteDoc(
|
||||
this.DocstoreManager.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
'main.tex',
|
||||
@@ -93,7 +82,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -113,7 +102,7 @@ describe('DocstoreManager', function () {
|
||||
this.request.patch = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 404 }, '')
|
||||
return this.DocstoreManager.deleteDoc(
|
||||
this.DocstoreManager.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
'main.tex',
|
||||
@@ -145,7 +134,7 @@ describe('DocstoreManager', function () {
|
||||
this.rev = 5
|
||||
this.version = 42
|
||||
this.ranges = { mock: 'ranges' }
|
||||
return (this.modified = true)
|
||||
this.modified = true
|
||||
})
|
||||
|
||||
describe('with a successful response code', function () {
|
||||
@@ -158,7 +147,7 @@ describe('DocstoreManager', function () {
|
||||
{ statusCode: 204 },
|
||||
{ modified: this.modified, rev: this.rev }
|
||||
)
|
||||
return this.DocstoreManager.updateDoc(
|
||||
this.DocstoreManager.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.lines,
|
||||
@@ -169,7 +158,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should update the doc in the docstore api', function () {
|
||||
return this.request.post
|
||||
this.request.post
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
||||
timeout: 30 * 1000,
|
||||
@@ -183,7 +172,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should call the callback with the modified status and revision', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(null, this.modified, this.rev)
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -194,7 +183,7 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.DocstoreManager.updateDoc(
|
||||
this.DocstoreManager.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.lines,
|
||||
@@ -205,7 +194,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -223,12 +212,12 @@ describe('DocstoreManager', function () {
|
||||
|
||||
describe('getDoc', function () {
|
||||
beforeEach(function () {
|
||||
return (this.doc = {
|
||||
this.doc = {
|
||||
lines: (this.lines = ['mock', 'doc', 'lines']),
|
||||
rev: (this.rev = 5),
|
||||
version: (this.version = 42),
|
||||
ranges: (this.ranges = { mock: 'ranges' }),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe('with a successful response code', function () {
|
||||
@@ -236,25 +225,19 @@ describe('DocstoreManager', function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 }, this.doc)
|
||||
return this.DocstoreManager.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.getDoc(this.project_id, this.doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should get the doc from the docstore api', function () {
|
||||
return this.request.get
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
||||
timeout: 30 * 1000,
|
||||
json: true,
|
||||
})
|
||||
.should.equal(true)
|
||||
this.request.get.should.have.been.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
||||
timeout: 30 * 1000,
|
||||
json: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the callback with the lines, version and rev', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(null, this.lines, this.rev, this.version, this.ranges)
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -265,15 +248,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.DocstoreManager.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.getDoc(this.project_id, this.doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -293,7 +272,7 @@ describe('DocstoreManager', function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 }, this.doc)
|
||||
return this.DocstoreManager.getDoc(
|
||||
this.DocstoreManager.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{ include_deleted: true },
|
||||
@@ -302,36 +281,53 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should get the doc from the docstore api (including deleted)', function () {
|
||||
return this.request.get
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}?include_deleted=true`,
|
||||
timeout: 30 * 1000,
|
||||
json: true,
|
||||
})
|
||||
.should.equal(true)
|
||||
this.request.get.should.have.been.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}`,
|
||||
qs: { include_deleted: 'true' },
|
||||
timeout: 30 * 1000,
|
||||
json: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should call the callback with the lines, version and rev', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(null, this.lines, this.rev, this.version, this.ranges)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with peek=true', function () {
|
||||
beforeEach(function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 }, this.doc)
|
||||
this.DocstoreManager.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{ peek: true },
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the docstore peek url', function () {
|
||||
this.request.get.should.have.been.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc/${this.doc_id}/peek`,
|
||||
timeout: 30 * 1000,
|
||||
json: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a missing (404) response code', function () {
|
||||
beforeEach(function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 404 }, '')
|
||||
return this.DocstoreManager.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.getDoc(this.project_id, this.doc_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Errors.NotFoundError)
|
||||
@@ -353,11 +349,11 @@ describe('DocstoreManager', function () {
|
||||
{ statusCode: 204 },
|
||||
(this.docs = [{ _id: 'mock-doc-id' }])
|
||||
)
|
||||
return this.DocstoreManager.getAllDocs(this.project_id, this.callback)
|
||||
this.DocstoreManager.getAllDocs(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should get all the project docs in the docstore api', function () {
|
||||
return this.request.get
|
||||
this.request.get
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/doc`,
|
||||
timeout: 30 * 1000,
|
||||
@@ -367,7 +363,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should call the callback with the docs', function () {
|
||||
return this.callback.calledWith(null, this.docs).should.equal(true)
|
||||
this.callback.calledWith(null, this.docs).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -376,11 +372,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.DocstoreManager.getAllDocs(this.project_id, this.callback)
|
||||
this.DocstoreManager.getAllDocs(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -473,11 +469,11 @@ describe('DocstoreManager', function () {
|
||||
{ statusCode: 204 },
|
||||
(this.docs = [{ _id: 'mock-doc-id', ranges: 'mock-ranges' }])
|
||||
)
|
||||
return this.DocstoreManager.getAllRanges(this.project_id, this.callback)
|
||||
this.DocstoreManager.getAllRanges(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should get all the project doc ranges in the docstore api', function () {
|
||||
return this.request.get
|
||||
this.request.get
|
||||
.calledWith({
|
||||
url: `${this.settings.apis.docstore.url}/project/${this.project_id}/ranges`,
|
||||
timeout: 30 * 1000,
|
||||
@@ -487,7 +483,7 @@ describe('DocstoreManager', function () {
|
||||
})
|
||||
|
||||
it('should call the callback with the docs', function () {
|
||||
return this.callback.calledWith(null, this.docs).should.equal(true)
|
||||
this.callback.calledWith(null, this.docs).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -496,11 +492,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.get = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 }, '')
|
||||
return this.DocstoreManager.getAllRanges(this.project_id, this.callback)
|
||||
this.DocstoreManager.getAllRanges(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -522,14 +518,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 })
|
||||
return this.DocstoreManager.archiveProject(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.archiveProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -538,14 +531,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 })
|
||||
return this.DocstoreManager.archiveProject(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.archiveProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -567,14 +557,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 })
|
||||
return this.DocstoreManager.unarchiveProject(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.unarchiveProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -583,14 +570,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 })
|
||||
return this.DocstoreManager.unarchiveProject(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.unarchiveProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
@@ -612,14 +596,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 204 })
|
||||
return this.DocstoreManager.destroyProject(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.destroyProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback', function () {
|
||||
return this.callback.called.should.equal(true)
|
||||
this.callback.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -628,14 +609,11 @@ describe('DocstoreManager', function () {
|
||||
this.request.post = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { statusCode: 500 })
|
||||
return this.DocstoreManager.destroyProject(
|
||||
this.project_id,
|
||||
this.callback
|
||||
)
|
||||
this.DocstoreManager.destroyProject(this.project_id, this.callback)
|
||||
})
|
||||
|
||||
it('should call the callback with an error', function () {
|
||||
return this.callback
|
||||
this.callback
|
||||
.calledWith(
|
||||
sinon.match
|
||||
.instanceOf(Error)
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
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
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Documents/DocumentController.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const events = require('events')
|
||||
const MockRequest = require('../helpers/MockRequest')
|
||||
const MockResponse = require('../helpers/MockResponse')
|
||||
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
||||
@@ -41,23 +27,23 @@ describe('DocumentController', function () {
|
||||
this.pathname = '/a/b/c/file.tex'
|
||||
this.lastUpdatedAt = new Date().getTime()
|
||||
this.lastUpdatedBy = 'fake-last-updater-id'
|
||||
return (this.rev = 5)
|
||||
this.rev = 5
|
||||
})
|
||||
|
||||
describe('getDocument', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.params = {
|
||||
this.req.params = {
|
||||
Project_id: this.project_id,
|
||||
doc_id: this.doc_id,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe('when the project exists without project history enabled', function () {
|
||||
beforeEach(function () {
|
||||
this.project = { _id: this.project_id }
|
||||
return (this.ProjectGetter.getProject = sinon
|
||||
this.ProjectGetter.getProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, this.project))
|
||||
.callsArgWith(2, null, this.project)
|
||||
})
|
||||
|
||||
describe('when the document exists', function () {
|
||||
@@ -68,29 +54,18 @@ describe('DocumentController', function () {
|
||||
.callsArgWith(1, null, this.doc, { fileSystem: this.pathname })
|
||||
this.ProjectEntityHandler.getDoc = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
2,
|
||||
null,
|
||||
this.doc_lines,
|
||||
this.rev,
|
||||
this.version,
|
||||
this.ranges
|
||||
)
|
||||
return this.DocumentController.getDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
.yields(null, this.doc_lines, this.rev, this.version, this.ranges)
|
||||
this.DocumentController.getDocument(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should get the project', function () {
|
||||
return this.ProjectGetter.getProject
|
||||
this.ProjectGetter.getProject
|
||||
.calledWith(this.project_id, { rootFolder: true, overleaf: true })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should get the pathname of the document', function () {
|
||||
return this.ProjectLocator.findElement
|
||||
this.ProjectLocator.findElement
|
||||
.calledWith({
|
||||
project: this.project,
|
||||
element_id: this.doc_id,
|
||||
@@ -100,14 +75,14 @@ describe('DocumentController', function () {
|
||||
})
|
||||
|
||||
it('should get the document content', function () {
|
||||
return this.ProjectEntityHandler.getDoc
|
||||
this.ProjectEntityHandler.getDoc
|
||||
.calledWith(this.project_id, this.doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return the document data to the client as JSON', function () {
|
||||
this.res.type.should.equal('application/json')
|
||||
return this.res.body.should.equal(
|
||||
this.res.body.should.equal(
|
||||
JSON.stringify({
|
||||
lines: this.doc_lines,
|
||||
version: this.version,
|
||||
@@ -123,15 +98,11 @@ describe('DocumentController', function () {
|
||||
this.ProjectLocator.findElement = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, new Errors.NotFoundError('not found'))
|
||||
return this.DocumentController.getDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
this.DocumentController.getDocument(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should call next with the NotFoundError', function () {
|
||||
return this.next
|
||||
this.next
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -161,24 +132,13 @@ describe('DocumentController', function () {
|
||||
.callsArgWith(1, null, this.doc, { fileSystem: this.pathname })
|
||||
this.ProjectEntityHandler.getDoc = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
2,
|
||||
null,
|
||||
this.doc_lines,
|
||||
this.rev,
|
||||
this.version,
|
||||
this.ranges
|
||||
)
|
||||
return this.DocumentController.getDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
.yields(null, this.doc_lines, this.rev, this.version, this.ranges)
|
||||
this.DocumentController.getDocument(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should return the history id and display setting to the client as JSON', function () {
|
||||
this.res.type.should.equal('application/json')
|
||||
return this.res.body.should.equal(
|
||||
this.res.body.should.equal(
|
||||
JSON.stringify({
|
||||
lines: this.doc_lines,
|
||||
version: this.version,
|
||||
@@ -215,14 +175,7 @@ describe('DocumentController', function () {
|
||||
.callsArgWith(1, null, this.doc, { fileSystem: this.pathname })
|
||||
this.ProjectEntityHandler.getDoc = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
2,
|
||||
null,
|
||||
this.doc_lines,
|
||||
this.rev,
|
||||
this.version,
|
||||
this.ranges
|
||||
)
|
||||
.yields(null, this.doc_lines, this.rev, this.version, this.ranges)
|
||||
return this.DocumentController.getDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
@@ -248,25 +201,21 @@ describe('DocumentController', function () {
|
||||
describe('when the project does not exist', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
|
||||
return this.DocumentController.getDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
this.DocumentController.getDocument(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('returns a 404', function () {
|
||||
return this.res.statusCode.should.equal(404)
|
||||
this.res.statusCode.should.equal(404)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('setDocument', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.params = {
|
||||
this.req.params = {
|
||||
Project_id: this.project_id,
|
||||
doc_id: this.doc_id,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe('when the document exists', function () {
|
||||
@@ -279,15 +228,11 @@ describe('DocumentController', function () {
|
||||
lastUpdatedAt: this.lastUpdatedAt,
|
||||
lastUpdatedBy: this.lastUpdatedBy,
|
||||
}
|
||||
return this.DocumentController.setDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
this.DocumentController.setDocument(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should update the document in Mongo', function () {
|
||||
return sinon.assert.calledWith(
|
||||
sinon.assert.calledWith(
|
||||
this.ProjectEntityUpdateHandler.updateDocLines,
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
@@ -300,7 +245,7 @@ describe('DocumentController', function () {
|
||||
})
|
||||
|
||||
it('should return a successful response', function () {
|
||||
return this.res.success.should.equal(true)
|
||||
this.res.success.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -310,15 +255,11 @@ describe('DocumentController', function () {
|
||||
.stub()
|
||||
.yields(new Errors.NotFoundError('document does not exist'))
|
||||
this.req.body = { lines: this.doc_lines }
|
||||
return this.DocumentController.setDocument(
|
||||
this.req,
|
||||
this.res,
|
||||
this.next
|
||||
)
|
||||
this.DocumentController.setDocument(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should call next with the NotFoundError', function () {
|
||||
return this.next
|
||||
this.next
|
||||
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user