mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
prettier auto-format
This commit is contained in:
@@ -21,8 +21,8 @@ const modulePath = require('path').join(
|
||||
)
|
||||
const { ObjectId } = require('mongojs')
|
||||
|
||||
describe('HttpController', function() {
|
||||
beforeEach(function() {
|
||||
describe('HttpController', function () {
|
||||
beforeEach(function () {
|
||||
this.HttpController = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./DocManager': (this.DocManager = {}),
|
||||
@@ -60,9 +60,9 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getDoc', function() {
|
||||
describe('without deleted docs', function() {
|
||||
beforeEach(function() {
|
||||
describe('getDoc', function () {
|
||||
describe('without deleted docs', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = {
|
||||
project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
@@ -73,13 +73,13 @@ describe('HttpController', function() {
|
||||
return this.HttpController.getDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should get the document with the version (including deleted)', function() {
|
||||
it('should get the document with the version (including deleted)', function () {
|
||||
return this.DocManager.getFullDoc
|
||||
.calledWith(this.project_id, this.doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the doc as JSON', function() {
|
||||
return it('should return the doc as JSON', function () {
|
||||
return this.res.json
|
||||
.calledWith({
|
||||
_id: this.doc_id,
|
||||
@@ -91,8 +91,8 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('which is deleted', function() {
|
||||
beforeEach(function() {
|
||||
return describe('which is deleted', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = {
|
||||
project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
@@ -102,19 +102,19 @@ describe('HttpController', function() {
|
||||
.callsArgWith(2, null, this.deletedDoc))
|
||||
})
|
||||
|
||||
it('should get the doc from the doc manager', function() {
|
||||
it('should get the doc from the doc manager', function () {
|
||||
this.HttpController.getDoc(this.req, this.res, this.next)
|
||||
return this.DocManager.getFullDoc
|
||||
.calledWith(this.project_id, this.doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should return 404 if the query string delete is not set ', function() {
|
||||
it('should return 404 if the query string delete is not set ', function () {
|
||||
this.HttpController.getDoc(this.req, this.res, this.next)
|
||||
return this.res.send.calledWith(404).should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the doc as JSON if include_deleted is set to true', function() {
|
||||
return it('should return the doc as JSON if include_deleted is set to true', function () {
|
||||
this.req.query.include_deleted = 'true'
|
||||
this.HttpController.getDoc(this.req, this.res, this.next)
|
||||
return this.res.json
|
||||
@@ -130,8 +130,8 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getRawDoc', function() {
|
||||
beforeEach(function() {
|
||||
describe('getRawDoc', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = {
|
||||
project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
@@ -140,19 +140,19 @@ describe('HttpController', function() {
|
||||
return this.HttpController.getRawDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should get the document without the version', function() {
|
||||
it('should get the document without the version', function () {
|
||||
return this.DocManager.getDocLines
|
||||
.calledWith(this.project_id, this.doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should set the content type header', function() {
|
||||
it('should set the content type header', function () {
|
||||
return this.res.setHeader
|
||||
.calledWith('content-type', 'text/plain')
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should send the raw version of the doc', function() {
|
||||
return it('should send the raw version of the doc', function () {
|
||||
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]}`
|
||||
@@ -160,9 +160,9 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllDocs', function() {
|
||||
describe('normally', function() {
|
||||
beforeEach(function() {
|
||||
describe('getAllDocs', function () {
|
||||
describe('normally', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = { project_id: this.project_id }
|
||||
this.docs = [
|
||||
{
|
||||
@@ -182,13 +182,13 @@ describe('HttpController', function() {
|
||||
return this.HttpController.getAllDocs(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should get all the (non-deleted) docs', function() {
|
||||
it('should get all the (non-deleted) docs', function () {
|
||||
return this.DocManager.getAllNonDeletedDocs
|
||||
.calledWith(this.project_id, { lines: true, rev: true })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the doc as JSON', function() {
|
||||
return it('should return the doc as JSON', function () {
|
||||
return this.res.json
|
||||
.calledWith([
|
||||
{
|
||||
@@ -206,8 +206,8 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
return describe('with a null doc', function() {
|
||||
beforeEach(function() {
|
||||
return describe('with a null doc', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = { project_id: this.project_id }
|
||||
this.docs = [
|
||||
{
|
||||
@@ -228,7 +228,7 @@ describe('HttpController', function() {
|
||||
return this.HttpController.getAllDocs(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should return the non null docs as JSON', function() {
|
||||
it('should return the non null docs as JSON', function () {
|
||||
return this.res.json
|
||||
.calledWith([
|
||||
{
|
||||
@@ -245,7 +245,7 @@ describe('HttpController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should log out an error', function() {
|
||||
return it('should log out an error', function () {
|
||||
return this.logger.error
|
||||
.calledWith(
|
||||
{
|
||||
@@ -259,9 +259,9 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllRanges', function() {
|
||||
return describe('normally', function() {
|
||||
beforeEach(function() {
|
||||
describe('getAllRanges', function () {
|
||||
return describe('normally', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = { project_id: this.project_id }
|
||||
this.docs = [
|
||||
{
|
||||
@@ -279,13 +279,13 @@ describe('HttpController', function() {
|
||||
return this.HttpController.getAllRanges(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should get all the (non-deleted) doc ranges', function() {
|
||||
it('should get all the (non-deleted) doc ranges', function () {
|
||||
return this.DocManager.getAllNonDeletedDocs
|
||||
.calledWith(this.project_id, { ranges: true })
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return the doc as JSON', function() {
|
||||
return it('should return the doc as JSON', function () {
|
||||
return this.res.json
|
||||
.calledWith([
|
||||
{
|
||||
@@ -302,16 +302,16 @@ describe('HttpController', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateDoc', function() {
|
||||
beforeEach(function() {
|
||||
describe('updateDoc', function () {
|
||||
beforeEach(function () {
|
||||
return (this.req.params = {
|
||||
project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the doc lines exist and were updated', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the doc lines exist and were updated', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body = {
|
||||
lines: (this.lines = ['hello', 'world']),
|
||||
version: (this.version = 42),
|
||||
@@ -323,7 +323,7 @@ describe('HttpController', function() {
|
||||
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should update the document', function() {
|
||||
it('should update the document', function () {
|
||||
return this.DocManager.updateDoc
|
||||
.calledWith(
|
||||
this.project_id,
|
||||
@@ -335,15 +335,15 @@ describe('HttpController', function() {
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return a modified status', function() {
|
||||
return it('should return a modified status', function () {
|
||||
return this.res.json
|
||||
.calledWith({ modified: true, rev: this.rev })
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the doc lines exist and were not updated', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the doc lines exist and were not updated', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body = {
|
||||
lines: (this.lines = ['hello', 'world']),
|
||||
version: (this.version = 42),
|
||||
@@ -355,63 +355,63 @@ describe('HttpController', function() {
|
||||
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
return it('should return a modified status', function() {
|
||||
return it('should return a modified status', function () {
|
||||
return this.res.json
|
||||
.calledWith({ modified: false, rev: this.rev })
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the doc lines are not provided', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the doc lines are not provided', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body = { version: 42, ranges: {} }
|
||||
this.DocManager.updateDoc = sinon.stub().yields(null, false)
|
||||
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should not update the document', function() {
|
||||
it('should not update the document', function () {
|
||||
return this.DocManager.updateDoc.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should return a 400 (bad request) response', function() {
|
||||
return it('should return a 400 (bad request) response', function () {
|
||||
return this.res.send.calledWith(400).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the doc version are not provided', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the doc version are not provided', function () {
|
||||
beforeEach(function () {
|
||||
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)
|
||||
})
|
||||
|
||||
it('should not update the document', function() {
|
||||
it('should not update the document', function () {
|
||||
return this.DocManager.updateDoc.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should return a 400 (bad request) response', function() {
|
||||
return it('should return a 400 (bad request) response', function () {
|
||||
return this.res.send.calledWith(400).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the doc ranges is not provided', function() {
|
||||
beforeEach(function() {
|
||||
describe('when the doc ranges is not provided', function () {
|
||||
beforeEach(function () {
|
||||
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)
|
||||
})
|
||||
|
||||
it('should not update the document', function() {
|
||||
it('should not update the document', function () {
|
||||
return this.DocManager.updateDoc.called.should.equal(false)
|
||||
})
|
||||
|
||||
return it('should return a 400 (bad request) response', function() {
|
||||
return it('should return a 400 (bad request) response', function () {
|
||||
return this.res.send.calledWith(400).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('when the doc body is too large', function() {
|
||||
beforeEach(function() {
|
||||
return describe('when the doc body is too large', function () {
|
||||
beforeEach(function () {
|
||||
this.req.body = {
|
||||
lines: (this.lines = Array(2049).fill('a'.repeat(1024))),
|
||||
version: (this.version = 42),
|
||||
@@ -420,18 +420,18 @@ describe('HttpController', function() {
|
||||
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should return a 413 (too large) response', function() {
|
||||
it('should return a 413 (too large) response', function () {
|
||||
return sinon.assert.calledWith(this.res.status, 413)
|
||||
})
|
||||
|
||||
return it('should report that the document body is too large', function() {
|
||||
return it('should report that the document body is too large', function () {
|
||||
return sinon.assert.calledWith(this.res.send, 'document body too large')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteDoc', function() {
|
||||
beforeEach(function() {
|
||||
describe('deleteDoc', function () {
|
||||
beforeEach(function () {
|
||||
this.req.params = {
|
||||
project_id: this.project_id,
|
||||
doc_id: this.doc_id
|
||||
@@ -440,50 +440,50 @@ describe('HttpController', function() {
|
||||
return this.HttpController.deleteDoc(this.req, this.res, this.next)
|
||||
})
|
||||
|
||||
it('should delete the document', function() {
|
||||
it('should delete the document', function () {
|
||||
return this.DocManager.deleteDoc
|
||||
.calledWith(this.project_id, this.doc_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return a 204 (No Content)', function() {
|
||||
return it('should return a 204 (No Content)', function () {
|
||||
return this.res.send.calledWith(204).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('archiveAllDocs', function() {
|
||||
beforeEach(function() {
|
||||
describe('archiveAllDocs', function () {
|
||||
beforeEach(function () {
|
||||
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)
|
||||
})
|
||||
|
||||
it('should archive the project', function() {
|
||||
it('should archive the project', function () {
|
||||
return this.DocArchiveManager.archiveAllDocs
|
||||
.calledWith(this.project_id)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
return it('should return a 204 (No Content)', function() {
|
||||
return it('should return a 204 (No Content)', function () {
|
||||
return this.res.send.calledWith(204).should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
return describe('destroyAllDocs', function() {
|
||||
beforeEach(function() {
|
||||
return describe('destroyAllDocs', function () {
|
||||
beforeEach(function () {
|
||||
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)
|
||||
})
|
||||
|
||||
it('should destroy the docs', function() {
|
||||
it('should destroy the docs', function () {
|
||||
return sinon.assert.calledWith(
|
||||
this.DocArchiveManager.destroyAllDocs,
|
||||
this.project_id
|
||||
)
|
||||
})
|
||||
|
||||
return it('should return 204', function() {
|
||||
return it('should return 204', function () {
|
||||
return sinon.assert.calledWith(this.res.send, 204)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user