2020-02-16 09:02:49 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-16 09:02:48 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-16 09:02:55 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const { assert } = require('chai')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const chai = require('chai')
|
|
|
|
chai.should()
|
|
|
|
const { expect } = chai
|
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/HttpController'
|
|
|
|
)
|
2020-08-21 12:50:01 -04:00
|
|
|
const { ObjectId } = require('mongodb')
|
2020-02-16 09:02:55 -05:00
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('HttpController', function () {
|
|
|
|
beforeEach(function () {
|
2020-09-10 13:07:14 -04:00
|
|
|
const settings = {
|
|
|
|
max_doc_length: 2 * 1024 * 1024
|
|
|
|
}
|
2020-02-16 09:02:55 -05:00
|
|
|
this.HttpController = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./DocManager': (this.DocManager = {}),
|
|
|
|
'./DocArchiveManager': (this.DocArchiveManager = {}),
|
|
|
|
'logger-sharelatex': (this.logger = {
|
|
|
|
log: sinon.stub(),
|
|
|
|
error: sinon.stub()
|
|
|
|
}),
|
2020-09-10 13:07:14 -04:00
|
|
|
'settings-sharelatex': settings,
|
2020-02-16 09:02:55 -05:00
|
|
|
'./HealthChecker': {}
|
2020-04-19 15:24:59 -04:00
|
|
|
},
|
|
|
|
globals: { process }
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
this.res = {
|
|
|
|
send: sinon.stub(),
|
2020-03-18 10:07:01 -04:00
|
|
|
sendStatus: sinon.stub(),
|
2020-02-16 09:02:55 -05:00
|
|
|
json: sinon.stub(),
|
|
|
|
setHeader: sinon.stub()
|
|
|
|
}
|
|
|
|
this.res.status = sinon.stub().returns(this.res)
|
|
|
|
this.req = { query: {} }
|
|
|
|
this.next = sinon.stub()
|
|
|
|
this.project_id = 'mock-project-id'
|
|
|
|
this.doc_id = 'mock-doc-id'
|
|
|
|
this.doc = {
|
|
|
|
_id: this.doc_id,
|
|
|
|
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
|
|
|
|
version: 42,
|
|
|
|
rev: 5
|
|
|
|
}
|
|
|
|
return (this.deletedDoc = {
|
|
|
|
deleted: true,
|
|
|
|
_id: this.doc_id,
|
|
|
|
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
|
|
|
|
version: 42,
|
|
|
|
rev: 5
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('getDoc', function () {
|
|
|
|
describe('without deleted docs', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = {
|
|
|
|
project_id: this.project_id,
|
|
|
|
doc_id: this.doc_id
|
|
|
|
}
|
|
|
|
this.DocManager.getFullDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.doc)
|
|
|
|
return this.HttpController.getDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should get the document with the version (including deleted)', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.getFullDoc
|
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return the doc as JSON', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.json
|
|
|
|
.calledWith({
|
|
|
|
_id: this.doc_id,
|
|
|
|
lines: this.doc.lines,
|
|
|
|
rev: this.doc.rev,
|
|
|
|
version: this.doc.version
|
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('which is deleted', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = {
|
|
|
|
project_id: this.project_id,
|
|
|
|
doc_id: this.doc_id
|
|
|
|
}
|
|
|
|
return (this.DocManager.getFullDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.deletedDoc))
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should get the doc from the doc manager', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.HttpController.getDoc(this.req, this.res, this.next)
|
|
|
|
return this.DocManager.getFullDoc
|
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return 404 if the query string delete is not set ', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.HttpController.getDoc(this.req, this.res, this.next)
|
2020-03-18 10:07:01 -04:00
|
|
|
return this.res.sendStatus.calledWith(404).should.equal(true)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return the doc as JSON if include_deleted is set to true', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.query.include_deleted = 'true'
|
|
|
|
this.HttpController.getDoc(this.req, this.res, this.next)
|
|
|
|
return this.res.json
|
|
|
|
.calledWith({
|
|
|
|
_id: this.doc_id,
|
|
|
|
lines: this.doc.lines,
|
|
|
|
rev: this.doc.rev,
|
|
|
|
deleted: true,
|
|
|
|
version: this.doc.version
|
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('getRawDoc', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = {
|
|
|
|
project_id: this.project_id,
|
|
|
|
doc_id: this.doc_id
|
|
|
|
}
|
|
|
|
this.DocManager.getDocLines = sinon.stub().callsArgWith(2, null, this.doc)
|
|
|
|
return this.HttpController.getRawDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should get the document without the version', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.getDocLines
|
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should set the content type header', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.setHeader
|
|
|
|
.calledWith('content-type', 'text/plain')
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should send the raw version of the doc', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return assert.deepEqual(
|
|
|
|
this.res.send.args[0][0],
|
|
|
|
`${this.doc.lines[0]}\n${this.doc.lines[1]}\n${this.doc.lines[2]}\n${this.doc.lines[3]}\n${this.doc.lines[4]}\n${this.doc.lines[5]}`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('getAllDocs', function () {
|
|
|
|
describe('normally', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.docs = [
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['mock', 'lines', 'one'],
|
|
|
|
rev: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['mock', 'lines', 'two'],
|
|
|
|
rev: 4
|
|
|
|
}
|
|
|
|
]
|
|
|
|
this.DocManager.getAllNonDeletedDocs = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.docs)
|
|
|
|
return this.HttpController.getAllDocs(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should get all the (non-deleted) docs', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.getAllNonDeletedDocs
|
|
|
|
.calledWith(this.project_id, { lines: true, rev: true })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return the doc as JSON', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.json
|
|
|
|
.calledWith([
|
|
|
|
{
|
|
|
|
_id: this.docs[0]._id.toString(),
|
|
|
|
lines: this.docs[0].lines,
|
|
|
|
rev: this.docs[0].rev
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: this.docs[1]._id.toString(),
|
|
|
|
lines: this.docs[1].lines,
|
|
|
|
rev: this.docs[1].rev
|
|
|
|
}
|
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('with a null doc', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.docs = [
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['mock', 'lines', 'one'],
|
|
|
|
rev: 2
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
lines: ['mock', 'lines', 'two'],
|
|
|
|
rev: 4
|
|
|
|
}
|
|
|
|
]
|
|
|
|
this.DocManager.getAllNonDeletedDocs = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.docs)
|
|
|
|
return this.HttpController.getAllDocs(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return the non null docs as JSON', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.json
|
|
|
|
.calledWith([
|
|
|
|
{
|
|
|
|
_id: this.docs[0]._id.toString(),
|
|
|
|
lines: this.docs[0].lines,
|
|
|
|
rev: this.docs[0].rev
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: this.docs[2]._id.toString(),
|
|
|
|
lines: this.docs[2].lines,
|
|
|
|
rev: this.docs[2].rev
|
|
|
|
}
|
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should log out an error', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.logger.error
|
|
|
|
.calledWith(
|
|
|
|
{
|
|
|
|
err: sinon.match.has('message', 'null doc'),
|
|
|
|
project_id: this.project_id
|
|
|
|
},
|
|
|
|
'encountered null doc'
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('getAllRanges', function () {
|
|
|
|
return describe('normally', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.docs = [
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
ranges: { mock_ranges: 'one' }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: ObjectId(),
|
|
|
|
ranges: { mock_ranges: 'two' }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
this.DocManager.getAllNonDeletedDocs = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(2, null, this.docs)
|
|
|
|
return this.HttpController.getAllRanges(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should get all the (non-deleted) doc ranges', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.getAllNonDeletedDocs
|
|
|
|
.calledWith(this.project_id, { ranges: true })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return the doc as JSON', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.json
|
|
|
|
.calledWith([
|
|
|
|
{
|
|
|
|
_id: this.docs[0]._id.toString(),
|
|
|
|
ranges: this.docs[0].ranges
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: this.docs[1]._id.toString(),
|
|
|
|
ranges: this.docs[1].ranges
|
|
|
|
}
|
|
|
|
])
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('updateDoc', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return (this.req.params = {
|
|
|
|
project_id: this.project_id,
|
|
|
|
doc_id: this.doc_id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc lines exist and were updated', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.body = {
|
|
|
|
lines: (this.lines = ['hello', 'world']),
|
|
|
|
version: (this.version = 42),
|
|
|
|
ranges: (this.ranges = { changes: 'mock' })
|
|
|
|
}
|
|
|
|
this.DocManager.updateDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, true, (this.rev = 5))
|
|
|
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should update the document', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.updateDoc
|
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.lines,
|
|
|
|
this.version,
|
|
|
|
this.ranges
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a modified status', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.json
|
|
|
|
.calledWith({ modified: true, rev: this.rev })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc lines exist and were not updated', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.body = {
|
|
|
|
lines: (this.lines = ['hello', 'world']),
|
|
|
|
version: (this.version = 42),
|
|
|
|
ranges: {}
|
|
|
|
}
|
|
|
|
this.DocManager.updateDoc = sinon
|
|
|
|
.stub()
|
|
|
|
.yields(null, false, (this.rev = 5))
|
|
|
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a modified status', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.res.json
|
|
|
|
.calledWith({ modified: false, rev: this.rev })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc lines are not provided', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.body = { version: 42, ranges: {} }
|
|
|
|
this.DocManager.updateDoc = sinon.stub().yields(null, false)
|
|
|
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should not update the document', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.updateDoc.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a 400 (bad request) response', function () {
|
2020-03-18 10:07:01 -04:00
|
|
|
return this.res.sendStatus.calledWith(400).should.equal(true)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc version are not provided', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.body = { version: 42, lines: ['hello world'] }
|
|
|
|
this.DocManager.updateDoc = sinon.stub().yields(null, false)
|
|
|
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should not update the document', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.updateDoc.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a 400 (bad request) response', function () {
|
2020-03-18 10:07:01 -04:00
|
|
|
return this.res.sendStatus.calledWith(400).should.equal(true)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('when the doc ranges is not provided', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.body = { lines: ['foo'], version: 42 }
|
|
|
|
this.DocManager.updateDoc = sinon.stub().yields(null, false)
|
|
|
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should not update the document', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.updateDoc.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a 400 (bad request) response', function () {
|
2020-03-18 10:07:01 -04:00
|
|
|
return this.res.sendStatus.calledWith(400).should.equal(true)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('when the doc body is too large', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.body = {
|
|
|
|
lines: (this.lines = Array(2049).fill('a'.repeat(1024))),
|
|
|
|
version: (this.version = 42),
|
|
|
|
ranges: (this.ranges = { changes: 'mock' })
|
|
|
|
}
|
|
|
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should return a 413 (too large) response', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return sinon.assert.calledWith(this.res.status, 413)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should report that the document body is too large', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return sinon.assert.calledWith(this.res.send, 'document body too large')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('deleteDoc', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = {
|
|
|
|
project_id: this.project_id,
|
|
|
|
doc_id: this.doc_id
|
|
|
|
}
|
|
|
|
this.DocManager.deleteDoc = sinon.stub().callsArg(2)
|
|
|
|
return this.HttpController.deleteDoc(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should delete the document', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocManager.deleteDoc
|
|
|
|
.calledWith(this.project_id, this.doc_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a 204 (No Content)', function () {
|
2020-03-18 10:07:01 -04:00
|
|
|
return this.res.sendStatus.calledWith(204).should.equal(true)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
describe('archiveAllDocs', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.DocArchiveManager.archiveAllDocs = sinon.stub().callsArg(1)
|
|
|
|
return this.HttpController.archiveAllDocs(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should archive the project', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return this.DocArchiveManager.archiveAllDocs
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return a 204 (No Content)', function () {
|
2020-03-18 10:07:01 -04:00
|
|
|
return this.res.sendStatus.calledWith(204).should.equal(true)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return describe('destroyAllDocs', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.DocArchiveManager.destroyAllDocs = sinon.stub().callsArg(1)
|
|
|
|
return this.HttpController.destroyAllDocs(this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
it('should destroy the docs', function () {
|
2020-02-16 09:02:55 -05:00
|
|
|
return sinon.assert.calledWith(
|
|
|
|
this.DocArchiveManager.destroyAllDocs,
|
|
|
|
this.project_id
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-28 09:20:54 -04:00
|
|
|
return it('should return 204', function () {
|
2020-03-18 10:07:01 -04:00
|
|
|
return sinon.assert.calledWith(this.res.sendStatus, 204)
|
2020-02-16 09:02:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|