mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-02 09:25:47 +00:00
prettier: convert test/acceptance decaffeinated files to Prettier format
This commit is contained in:
parent
7e131e4c71
commit
785a6cb544
7 changed files with 2012 additions and 1117 deletions
File diff suppressed because one or more lines are too long
|
@ -11,119 +11,149 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require("sinon");
|
||||
const chai = require("chai");
|
||||
chai.should();
|
||||
const {db, ObjectId} = require("../../../app/js/mongojs");
|
||||
const {
|
||||
expect
|
||||
} = chai;
|
||||
const DocstoreApp = require("./helpers/DocstoreApp");
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
chai.should()
|
||||
const { db, ObjectId } = require('../../../app/js/mongojs')
|
||||
const { expect } = chai
|
||||
const DocstoreApp = require('./helpers/DocstoreApp')
|
||||
|
||||
const DocstoreClient = require("./helpers/DocstoreClient");
|
||||
const DocstoreClient = require('./helpers/DocstoreClient')
|
||||
|
||||
describe("Deleting a doc", function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId();
|
||||
this.doc_id = ObjectId();
|
||||
this.lines = ["original", "lines"];
|
||||
this.version = 42;
|
||||
this.ranges = [];
|
||||
return DocstoreApp.ensureRunning(() => {
|
||||
return DocstoreClient.createDoc(this.project_id, this.doc_id, this.lines, this.version, this.ranges, error => {
|
||||
if (error != null) { throw error; }
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Deleting a doc', function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId()
|
||||
this.doc_id = ObjectId()
|
||||
this.lines = ['original', 'lines']
|
||||
this.version = 42
|
||||
this.ranges = []
|
||||
return DocstoreApp.ensureRunning(() => {
|
||||
return DocstoreClient.createDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.lines,
|
||||
this.version,
|
||||
this.ranges,
|
||||
error => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the doc exists", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.deleteDoc(this.project_id, this.doc_id, (error, res, doc) => {
|
||||
this.res = res;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when the doc exists', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.deleteDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
(error, res, doc) => {
|
||||
this.res = res
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(function(done) {
|
||||
return db.docs.remove({_id: this.doc_id}, done);
|
||||
});
|
||||
afterEach(function(done) {
|
||||
return db.docs.remove({ _id: this.doc_id }, done)
|
||||
})
|
||||
|
||||
return it("should insert a deleted doc into the docs collection", function(done) {
|
||||
return db.docs.find({_id: this.doc_id}, (error, docs) => {
|
||||
docs[0]._id.should.deep.equal(this.doc_id);
|
||||
docs[0].lines.should.deep.equal(this.lines);
|
||||
docs[0].deleted.should.equal(true);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should insert a deleted doc into the docs collection', function(done) {
|
||||
return db.docs.find({ _id: this.doc_id }, (error, docs) => {
|
||||
docs[0]._id.should.deep.equal(this.doc_id)
|
||||
docs[0].lines.should.deep.equal(this.lines)
|
||||
docs[0].deleted.should.equal(true)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return describe("when the doc does not exist", function() { return it("should return a 404", function(done) {
|
||||
const missing_doc_id = ObjectId();
|
||||
return DocstoreClient.deleteDoc(this.project_id, missing_doc_id, (error, res, doc) => {
|
||||
res.statusCode.should.equal(404);
|
||||
return done();
|
||||
});
|
||||
}); });
|
||||
});
|
||||
return describe('when the doc does not exist', function() {
|
||||
return it('should return a 404', function(done) {
|
||||
const missing_doc_id = ObjectId()
|
||||
return DocstoreClient.deleteDoc(
|
||||
this.project_id,
|
||||
missing_doc_id,
|
||||
(error, res, doc) => {
|
||||
res.statusCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("Destroying a project's documents", function() {
|
||||
describe("when the doc exists", function() {
|
||||
beforeEach(function(done) {
|
||||
return db.docOps.insert({doc_id: ObjectId(this.doc_id), version: 1}, function(err) {
|
||||
if (err != null) { return done(err); }
|
||||
return DocstoreClient.destroyAllDoc(this.project_id, done);
|
||||
});
|
||||
});
|
||||
describe('when the doc exists', function() {
|
||||
beforeEach(function(done) {
|
||||
return db.docOps.insert(
|
||||
{ doc_id: ObjectId(this.doc_id), version: 1 },
|
||||
function(err) {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
return DocstoreClient.destroyAllDoc(this.project_id, done)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should remove the doc from the docs collection", function(done) {
|
||||
return db.docs.find({_id: this.doc_id}, (err, docs) => {
|
||||
expect(err).not.to.exist;
|
||||
expect(docs).to.deep.equal([]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('should remove the doc from the docs collection', function(done) {
|
||||
return db.docs.find({ _id: this.doc_id }, (err, docs) => {
|
||||
expect(err).not.to.exist
|
||||
expect(docs).to.deep.equal([])
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
return it("should remove the docOps from the docOps collection", function(done) {
|
||||
return db.docOps.find({doc_id: this.doc_id}, (err, docOps) => {
|
||||
expect(err).not.to.exist;
|
||||
expect(docOps).to.deep.equal([]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should remove the docOps from the docOps collection', function(done) {
|
||||
return db.docOps.find({ doc_id: this.doc_id }, (err, docOps) => {
|
||||
expect(err).not.to.exist
|
||||
expect(docOps).to.deep.equal([])
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return describe("when the doc is archived", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.archiveAllDoc(this.project_id, function(err) {
|
||||
if (err != null) { return done(err); }
|
||||
return DocstoreClient.destroyAllDoc(this.project_id, done);
|
||||
});
|
||||
});
|
||||
return describe('when the doc is archived', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.archiveAllDoc(this.project_id, function(err) {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
return DocstoreClient.destroyAllDoc(this.project_id, done)
|
||||
})
|
||||
})
|
||||
|
||||
it("should remove the doc from the docs collection", function(done) {
|
||||
return db.docs.find({_id: this.doc_id}, (err, docs) => {
|
||||
expect(err).not.to.exist;
|
||||
expect(docs).to.deep.equal([]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('should remove the doc from the docs collection', function(done) {
|
||||
return db.docs.find({ _id: this.doc_id }, (err, docs) => {
|
||||
expect(err).not.to.exist
|
||||
expect(docs).to.deep.equal([])
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it("should remove the docOps from the docOps collection", function(done) {
|
||||
return db.docOps.find({doc_id: this.doc_id}, (err, docOps) => {
|
||||
expect(err).not.to.exist;
|
||||
expect(docOps).to.deep.equal([]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('should remove the docOps from the docOps collection', function(done) {
|
||||
return db.docOps.find({ doc_id: this.doc_id }, (err, docOps) => {
|
||||
expect(err).not.to.exist
|
||||
expect(docOps).to.deep.equal([])
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
return it("should remove the doc contents from s3", function(done) {
|
||||
return DocstoreClient.getS3Doc(this.project_id, this.doc_id, (error, res, s3_doc) => {
|
||||
if (error != null) { throw error; }
|
||||
expect(res.statusCode).to.equal(404);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should remove the doc contents from s3', function(done) {
|
||||
return DocstoreClient.getS3Doc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
(error, res, s3_doc) => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
expect(res.statusCode).to.equal(404)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -11,79 +11,104 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require("sinon");
|
||||
const chai = require("chai");
|
||||
chai.should();
|
||||
const {ObjectId} = require("mongojs");
|
||||
const async = require("async");
|
||||
const DocstoreApp = require("./helpers/DocstoreApp");
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
chai.should()
|
||||
const { ObjectId } = require('mongojs')
|
||||
const async = require('async')
|
||||
const DocstoreApp = require('./helpers/DocstoreApp')
|
||||
|
||||
const DocstoreClient = require("./helpers/DocstoreClient");
|
||||
const DocstoreClient = require('./helpers/DocstoreClient')
|
||||
|
||||
describe("Getting all docs", function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId();
|
||||
this.docs = [{
|
||||
_id: ObjectId(),
|
||||
lines: ["one", "two", "three"],
|
||||
ranges: {"mock": "one"},
|
||||
rev: 2
|
||||
}, {
|
||||
_id: ObjectId(),
|
||||
lines: ["aaa", "bbb", "ccc"],
|
||||
ranges: {"mock": "two"},
|
||||
rev: 4
|
||||
}, {
|
||||
_id: ObjectId(),
|
||||
lines: ["111", "222", "333"],
|
||||
ranges: {"mock": "three"},
|
||||
rev: 6
|
||||
}];
|
||||
this.deleted_doc = {
|
||||
_id: ObjectId(),
|
||||
lines: ["deleted"],
|
||||
ranges: {"mock": "four"},
|
||||
rev: 8
|
||||
};
|
||||
const version = 42;
|
||||
const jobs = Array.from(this.docs).map((doc) =>
|
||||
(doc => {
|
||||
return callback => {
|
||||
return DocstoreClient.createDoc(this.project_id, doc._id, doc.lines, version, doc.ranges, callback);
|
||||
};
|
||||
})(doc));
|
||||
jobs.push(cb => {
|
||||
return DocstoreClient.createDoc(this.project_id, this.deleted_doc._id, this.deleted_doc.lines, version, this.deleted_doc.ranges, err=> {
|
||||
return DocstoreClient.deleteDoc(this.project_id, this.deleted_doc._id, cb);
|
||||
});
|
||||
});
|
||||
jobs.unshift(cb => DocstoreApp.ensureRunning(cb));
|
||||
return async.series(jobs, done);
|
||||
});
|
||||
|
||||
it("getAllDocs should return all the (non-deleted) docs", function(done) {
|
||||
return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => {
|
||||
if (error != null) { throw error; }
|
||||
docs.length.should.equal(this.docs.length);
|
||||
for (let i = 0; i < docs.length; i++) {
|
||||
const doc = docs[i];
|
||||
doc.lines.should.deep.equal(this.docs[i].lines);
|
||||
}
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
return it("getAllRanges should return all the (non-deleted) doc ranges", function(done) {
|
||||
return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => {
|
||||
if (error != null) { throw error; }
|
||||
docs.length.should.equal(this.docs.length);
|
||||
for (let i = 0; i < docs.length; i++) {
|
||||
const doc = docs[i];
|
||||
doc.ranges.should.deep.equal(this.docs[i].ranges);
|
||||
}
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Getting all docs', function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId()
|
||||
this.docs = [
|
||||
{
|
||||
_id: ObjectId(),
|
||||
lines: ['one', 'two', 'three'],
|
||||
ranges: { mock: 'one' },
|
||||
rev: 2
|
||||
},
|
||||
{
|
||||
_id: ObjectId(),
|
||||
lines: ['aaa', 'bbb', 'ccc'],
|
||||
ranges: { mock: 'two' },
|
||||
rev: 4
|
||||
},
|
||||
{
|
||||
_id: ObjectId(),
|
||||
lines: ['111', '222', '333'],
|
||||
ranges: { mock: 'three' },
|
||||
rev: 6
|
||||
}
|
||||
]
|
||||
this.deleted_doc = {
|
||||
_id: ObjectId(),
|
||||
lines: ['deleted'],
|
||||
ranges: { mock: 'four' },
|
||||
rev: 8
|
||||
}
|
||||
const version = 42
|
||||
const jobs = Array.from(this.docs).map(doc =>
|
||||
(doc => {
|
||||
return callback => {
|
||||
return DocstoreClient.createDoc(
|
||||
this.project_id,
|
||||
doc._id,
|
||||
doc.lines,
|
||||
version,
|
||||
doc.ranges,
|
||||
callback
|
||||
)
|
||||
}
|
||||
})(doc)
|
||||
)
|
||||
jobs.push(cb => {
|
||||
return DocstoreClient.createDoc(
|
||||
this.project_id,
|
||||
this.deleted_doc._id,
|
||||
this.deleted_doc.lines,
|
||||
version,
|
||||
this.deleted_doc.ranges,
|
||||
err => {
|
||||
return DocstoreClient.deleteDoc(
|
||||
this.project_id,
|
||||
this.deleted_doc._id,
|
||||
cb
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
jobs.unshift(cb => DocstoreApp.ensureRunning(cb))
|
||||
return async.series(jobs, done)
|
||||
})
|
||||
|
||||
it('getAllDocs should return all the (non-deleted) docs', function(done) {
|
||||
return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
docs.length.should.equal(this.docs.length)
|
||||
for (let i = 0; i < docs.length; i++) {
|
||||
const doc = docs[i]
|
||||
doc.lines.should.deep.equal(this.docs[i].lines)
|
||||
}
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
return it('getAllRanges should return all the (non-deleted) doc ranges', function(done) {
|
||||
return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
docs.length.should.equal(this.docs.length)
|
||||
for (let i = 0; i < docs.length; i++) {
|
||||
const doc = docs[i]
|
||||
doc.ranges.should.deep.equal(this.docs[i].ranges)
|
||||
}
|
||||
return done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -11,80 +11,127 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require("sinon");
|
||||
const chai = require("chai");
|
||||
chai.should();
|
||||
const {ObjectId} = require("mongojs");
|
||||
const DocstoreApp = require("./helpers/DocstoreApp");
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
chai.should()
|
||||
const { ObjectId } = require('mongojs')
|
||||
const DocstoreApp = require('./helpers/DocstoreApp')
|
||||
|
||||
const DocstoreClient = require("./helpers/DocstoreClient");
|
||||
const DocstoreClient = require('./helpers/DocstoreClient')
|
||||
|
||||
describe("Getting a doc", function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId();
|
||||
this.doc_id = ObjectId();
|
||||
this.lines = ["original", "lines"];
|
||||
this.version = 42;
|
||||
this.ranges = {
|
||||
changes: [{
|
||||
id: ObjectId().toString(),
|
||||
op: { i: "foo", p: 3 },
|
||||
meta: {
|
||||
user_id: ObjectId().toString(),
|
||||
ts: new Date().toString()
|
||||
}
|
||||
}]
|
||||
};
|
||||
return DocstoreApp.ensureRunning(() => {
|
||||
return DocstoreClient.createDoc(this.project_id, this.doc_id, this.lines, this.version, this.ranges, error => {
|
||||
if (error != null) { throw error; }
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Getting a doc', function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId()
|
||||
this.doc_id = ObjectId()
|
||||
this.lines = ['original', 'lines']
|
||||
this.version = 42
|
||||
this.ranges = {
|
||||
changes: [
|
||||
{
|
||||
id: ObjectId().toString(),
|
||||
op: { i: 'foo', p: 3 },
|
||||
meta: {
|
||||
user_id: ObjectId().toString(),
|
||||
ts: new Date().toString()
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
return DocstoreApp.ensureRunning(() => {
|
||||
return DocstoreClient.createDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.lines,
|
||||
this.version,
|
||||
this.ranges,
|
||||
error => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the doc exists", function() { return it("should get the doc lines and version", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.lines);
|
||||
doc.version.should.equal(this.version);
|
||||
doc.ranges.should.deep.equal(this.ranges);
|
||||
return done();
|
||||
});
|
||||
}); });
|
||||
describe('when the doc exists', function() {
|
||||
return it('should get the doc lines and version', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.lines)
|
||||
doc.version.should.equal(this.version)
|
||||
doc.ranges.should.deep.equal(this.ranges)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the doc does not exist", function() { return it("should return a 404", function(done) {
|
||||
const missing_doc_id = ObjectId();
|
||||
return DocstoreClient.getDoc(this.project_id, missing_doc_id, {}, (error, res, doc) => {
|
||||
res.statusCode.should.equal(404);
|
||||
return done();
|
||||
});
|
||||
}); });
|
||||
describe('when the doc does not exist', function() {
|
||||
return it('should return a 404', function(done) {
|
||||
const missing_doc_id = ObjectId()
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
missing_doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
res.statusCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
return describe("when the doc is a deleted doc", function() {
|
||||
beforeEach(function(done) {
|
||||
this.deleted_doc_id = ObjectId();
|
||||
return DocstoreClient.createDoc(this.project_id, this.deleted_doc_id, this.lines, this.version, this.ranges, error => {
|
||||
if (error != null) { throw error; }
|
||||
return DocstoreClient.deleteDoc(this.project_id, this.deleted_doc_id, done);
|
||||
});
|
||||
});
|
||||
return describe('when the doc is a deleted doc', function() {
|
||||
beforeEach(function(done) {
|
||||
this.deleted_doc_id = ObjectId()
|
||||
return DocstoreClient.createDoc(
|
||||
this.project_id,
|
||||
this.deleted_doc_id,
|
||||
this.lines,
|
||||
this.version,
|
||||
this.ranges,
|
||||
error => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
return DocstoreClient.deleteDoc(
|
||||
this.project_id,
|
||||
this.deleted_doc_id,
|
||||
done
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return the doc", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.deleted_doc_id, {include_deleted:true},(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.lines);
|
||||
doc.version.should.equal(this.version);
|
||||
doc.ranges.should.deep.equal(this.ranges);
|
||||
doc.deleted.should.equal(true);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('should return the doc', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.deleted_doc_id,
|
||||
{ include_deleted: true },
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.lines)
|
||||
doc.version.should.equal(this.version)
|
||||
doc.ranges.should.deep.equal(this.ranges)
|
||||
doc.deleted.should.equal(true)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return it("should return a 404 when the query string is not set", function(done){
|
||||
return DocstoreClient.getDoc(this.project_id, this.deleted_doc_id, {},(error, res, doc) => {
|
||||
res.statusCode.should.equal(404);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return it('should return a 404 when the query string is not set', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.deleted_doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
res.statusCode.should.equal(404)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -10,329 +10,490 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require("sinon");
|
||||
const chai = require("chai");
|
||||
chai.should();
|
||||
const {ObjectId} = require("mongojs");
|
||||
const DocstoreApp = require("./helpers/DocstoreApp");
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
chai.should()
|
||||
const { ObjectId } = require('mongojs')
|
||||
const DocstoreApp = require('./helpers/DocstoreApp')
|
||||
|
||||
const DocstoreClient = require("./helpers/DocstoreClient");
|
||||
const DocstoreClient = require('./helpers/DocstoreClient')
|
||||
|
||||
describe("Applying updates to a doc", function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId();
|
||||
this.doc_id = ObjectId();
|
||||
this.originalLines = ["original", "lines"];
|
||||
this.newLines = ["new", "lines"];
|
||||
this.originalRanges = {
|
||||
changes: [{
|
||||
id: ObjectId().toString(),
|
||||
op: { i: "foo", p: 3 },
|
||||
meta: {
|
||||
user_id: ObjectId().toString(),
|
||||
ts: new Date().toString()
|
||||
}
|
||||
}]
|
||||
};
|
||||
this.newRanges = {
|
||||
changes: [{
|
||||
id: ObjectId().toString(),
|
||||
op: { i: "bar", p: 6 },
|
||||
meta: {
|
||||
user_id: ObjectId().toString(),
|
||||
ts: new Date().toString()
|
||||
}
|
||||
}]
|
||||
};
|
||||
this.version = 42;
|
||||
return DocstoreApp.ensureRunning(() => {
|
||||
return DocstoreClient.createDoc(this.project_id, this.doc_id, this.originalLines, this.version, this.originalRanges, error => {
|
||||
if (error != null) { throw error; }
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Applying updates to a doc', function() {
|
||||
beforeEach(function(done) {
|
||||
this.project_id = ObjectId()
|
||||
this.doc_id = ObjectId()
|
||||
this.originalLines = ['original', 'lines']
|
||||
this.newLines = ['new', 'lines']
|
||||
this.originalRanges = {
|
||||
changes: [
|
||||
{
|
||||
id: ObjectId().toString(),
|
||||
op: { i: 'foo', p: 3 },
|
||||
meta: {
|
||||
user_id: ObjectId().toString(),
|
||||
ts: new Date().toString()
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
this.newRanges = {
|
||||
changes: [
|
||||
{
|
||||
id: ObjectId().toString(),
|
||||
op: { i: 'bar', p: 6 },
|
||||
meta: {
|
||||
user_id: ObjectId().toString(),
|
||||
ts: new Date().toString()
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
this.version = 42
|
||||
return DocstoreApp.ensureRunning(() => {
|
||||
return DocstoreClient.createDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.originalLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
error => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when nothing has been updated", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when nothing has been updated', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.originalLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return modified = false", function() {
|
||||
return this.body.modified.should.equal(false);
|
||||
});
|
||||
it('should return modified = false', function() {
|
||||
return this.body.modified.should.equal(false)
|
||||
})
|
||||
|
||||
return it("should not update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
doc.version.should.equal(this.version);
|
||||
doc.ranges.should.deep.equal(this.originalRanges);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should not update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
doc.version.should.equal(this.version)
|
||||
doc.ranges.should.deep.equal(this.originalRanges)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the lines have changed", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.newLines, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when the lines have changed', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.newLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return modified = true", function() {
|
||||
return this.body.modified.should.equal(true);
|
||||
});
|
||||
it('should return modified = true', function() {
|
||||
return this.body.modified.should.equal(true)
|
||||
})
|
||||
|
||||
it("should return the rev", function() {
|
||||
return this.body.rev.should.equal(2);
|
||||
});
|
||||
it('should return the rev', function() {
|
||||
return this.body.rev.should.equal(2)
|
||||
})
|
||||
|
||||
return it("should update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.newLines);
|
||||
doc.version.should.equal(this.version);
|
||||
doc.ranges.should.deep.equal(this.originalRanges);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.newLines)
|
||||
doc.version.should.equal(this.version)
|
||||
doc.ranges.should.deep.equal(this.originalRanges)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the version has changed", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, this.version + 1, this.originalRanges, (error, res, body) => {
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when the version has changed', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.originalLines,
|
||||
this.version + 1,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return modified = true", function() {
|
||||
return this.body.modified.should.equal(true);
|
||||
});
|
||||
it('should return modified = true', function() {
|
||||
return this.body.modified.should.equal(true)
|
||||
})
|
||||
|
||||
it("should return the rev", function() {
|
||||
return this.body.rev.should.equal(1);
|
||||
});
|
||||
it('should return the rev', function() {
|
||||
return this.body.rev.should.equal(1)
|
||||
})
|
||||
|
||||
return it("should update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
doc.version.should.equal(this.version + 1);
|
||||
doc.ranges.should.deep.equal(this.originalRanges);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
doc.version.should.equal(this.version + 1)
|
||||
doc.ranges.should.deep.equal(this.originalRanges)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the ranges have changed", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, this.version, this.newRanges, (error, res, body) => {
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when the ranges have changed', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.originalLines,
|
||||
this.version,
|
||||
this.newRanges,
|
||||
(error, res, body) => {
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return modified = true", function() {
|
||||
return this.body.modified.should.equal(true);
|
||||
});
|
||||
it('should return modified = true', function() {
|
||||
return this.body.modified.should.equal(true)
|
||||
})
|
||||
|
||||
it("should return the rev", function() {
|
||||
return this.body.rev.should.equal(2);
|
||||
});
|
||||
it('should return the rev', function() {
|
||||
return this.body.rev.should.equal(2)
|
||||
})
|
||||
|
||||
return it("should update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
doc.version.should.equal(this.version);
|
||||
doc.ranges.should.deep.equal(this.newRanges);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
doc.version.should.equal(this.version)
|
||||
doc.ranges.should.deep.equal(this.newRanges)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the doc does not exist", function() {
|
||||
beforeEach(function(done) {
|
||||
this.missing_doc_id = ObjectId();
|
||||
return DocstoreClient.updateDoc(this.project_id, this.missing_doc_id, this.originalLines, 0, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when the doc does not exist', function() {
|
||||
beforeEach(function(done) {
|
||||
this.missing_doc_id = ObjectId()
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.missing_doc_id,
|
||||
this.originalLines,
|
||||
0,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create the doc", function() {
|
||||
return this.body.rev.should.equal(1);
|
||||
});
|
||||
it('should create the doc', function() {
|
||||
return this.body.rev.should.equal(1)
|
||||
})
|
||||
|
||||
return it("should be retreivable", function(done){
|
||||
return DocstoreClient.getDoc(this.project_id, this.missing_doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
doc.version.should.equal(0);
|
||||
doc.ranges.should.deep.equal(this.originalRanges);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should be retreivable', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.missing_doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
doc.version.should.equal(0)
|
||||
doc.ranges.should.deep.equal(this.originalRanges)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when malformed doc lines are provided", function() {
|
||||
describe("when the lines are not an array", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, { foo: "bar" }, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('when malformed doc lines are provided', function() {
|
||||
describe('when the lines are not an array', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{ foo: 'bar' },
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return 400", function() {
|
||||
return this.res.statusCode.should.equal(400);
|
||||
});
|
||||
it('should return 400', function() {
|
||||
return this.res.statusCode.should.equal(400)
|
||||
})
|
||||
|
||||
return it("should not update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
return it('should not update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
return describe("when the lines are not present", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, null, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
return describe('when the lines are not present', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
null,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should return 400", function() {
|
||||
return this.res.statusCode.should.equal(400);
|
||||
});
|
||||
it('should return 400', function() {
|
||||
return this.res.statusCode.should.equal(400)
|
||||
})
|
||||
|
||||
return it("should not update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when no version is provided", function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.originalLines, null, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
return it('should not update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("should return 400", function() {
|
||||
return this.res.statusCode.should.equal(400);
|
||||
});
|
||||
describe('when no version is provided', function() {
|
||||
beforeEach(function(done) {
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.originalLines,
|
||||
null,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return it("should not update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
doc.version.should.equal(this.version);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should return 400', function() {
|
||||
return this.res.statusCode.should.equal(400)
|
||||
})
|
||||
|
||||
describe("when the content is large", function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join("x"); // 1kb
|
||||
this.largeLines = Array.apply(null, Array(1024)).map(() => line); // 1mb
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
return it('should not update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
doc.version.should.equal(this.version)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("should return modified = true", function() {
|
||||
return this.body.modified.should.equal(true);
|
||||
});
|
||||
describe('when the content is large', function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join('x') // 1kb
|
||||
this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1mb
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.largeLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return it("should update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.largeLines);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should return modified = true', function() {
|
||||
return this.body.modified.should.equal(true)
|
||||
})
|
||||
|
||||
describe("when there is a large json payload", function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join("x"); // 1kb
|
||||
this.largeLines = Array.apply(null, Array(1024)).map(() => line); // 1kb
|
||||
this.originalRanges.padding = Array.apply(null, Array(2049)).map(() => line); // 2mb + 1kb
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
return it('should update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.largeLines)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("should return modified = true", function() {
|
||||
return this.body.modified.should.equal(true);
|
||||
});
|
||||
describe('when there is a large json payload', function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join('x') // 1kb
|
||||
this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1kb
|
||||
this.originalRanges.padding = Array.apply(null, Array(2049)).map(
|
||||
() => line
|
||||
) // 2mb + 1kb
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.largeLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return it("should update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.largeLines);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should return modified = true', function() {
|
||||
return this.body.modified.should.equal(true)
|
||||
})
|
||||
|
||||
describe("when the document body is too large", function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join("x"); // 1kb
|
||||
this.largeLines = Array.apply(null, Array(2049)).map(() => line); // 2mb + 1kb
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
return it('should update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.largeLines)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("should return 413", function() {
|
||||
return this.res.statusCode.should.equal(413);
|
||||
});
|
||||
describe('when the document body is too large', function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join('x') // 1kb
|
||||
this.largeLines = Array.apply(null, Array(2049)).map(() => line) // 2mb + 1kb
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.largeLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should report body too large", function() {
|
||||
return this.res.body.should.equal('document body too large');
|
||||
});
|
||||
it('should return 413', function() {
|
||||
return this.res.statusCode.should.equal(413)
|
||||
})
|
||||
|
||||
return it("should not update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should report body too large', function() {
|
||||
return this.res.body.should.equal('document body too large')
|
||||
})
|
||||
|
||||
return describe("when the json payload is too large", function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join("x"); // 1kb
|
||||
this.largeLines = Array.apply(null, Array(1024)).map(() => line); // 1kb
|
||||
this.originalRanges.padding = Array.apply(null, Array(4096)).map(() => line); // 4mb
|
||||
return DocstoreClient.updateDoc(this.project_id, this.doc_id, this.largeLines, this.version, this.originalRanges, (error, res, body) => {
|
||||
this.res = res;
|
||||
this.body = body;
|
||||
return done();
|
||||
});
|
||||
});
|
||||
return it('should not update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
return it("should not update the doc in the API", function(done) {
|
||||
return DocstoreClient.getDoc(this.project_id, this.doc_id, {}, (error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return describe('when the json payload is too large', function() {
|
||||
beforeEach(function(done) {
|
||||
const line = new Array(1025).join('x') // 1kb
|
||||
this.largeLines = Array.apply(null, Array(1024)).map(() => line) // 1kb
|
||||
this.originalRanges.padding = Array.apply(null, Array(4096)).map(
|
||||
() => line
|
||||
) // 4mb
|
||||
return DocstoreClient.updateDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
this.largeLines,
|
||||
this.version,
|
||||
this.originalRanges,
|
||||
(error, res, body) => {
|
||||
this.res = res
|
||||
this.body = body
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return it('should not update the doc in the API', function(done) {
|
||||
return DocstoreClient.getDoc(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
{},
|
||||
(error, res, doc) => {
|
||||
doc.lines.should.deep.equal(this.originalLines)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -11,34 +11,38 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const app = require('../../../../app');
|
||||
require("logger-sharelatex").logger.level("error");
|
||||
const settings = require("settings-sharelatex");
|
||||
const app = require('../../../../app')
|
||||
require('logger-sharelatex').logger.level('error')
|
||||
const settings = require('settings-sharelatex')
|
||||
|
||||
module.exports = {
|
||||
running: false,
|
||||
initing: false,
|
||||
callbacks: [],
|
||||
ensureRunning(callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
if (this.running) {
|
||||
return callback();
|
||||
} else if (this.initing) {
|
||||
return this.callbacks.push(callback);
|
||||
} else {
|
||||
this.initing = true;
|
||||
this.callbacks.push(callback);
|
||||
return app.listen(settings.internal.docstore.port, "localhost", error => {
|
||||
if (error != null) { throw error; }
|
||||
this.running = true;
|
||||
return (() => {
|
||||
const result = [];
|
||||
for (callback of Array.from(this.callbacks)) {
|
||||
result.push(callback());
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
running: false,
|
||||
initing: false,
|
||||
callbacks: [],
|
||||
ensureRunning(callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
}
|
||||
if (this.running) {
|
||||
return callback()
|
||||
} else if (this.initing) {
|
||||
return this.callbacks.push(callback)
|
||||
} else {
|
||||
this.initing = true
|
||||
this.callbacks.push(callback)
|
||||
return app.listen(settings.internal.docstore.port, 'localhost', error => {
|
||||
if (error != null) {
|
||||
throw error
|
||||
}
|
||||
this.running = true
|
||||
return (() => {
|
||||
const result = []
|
||||
for (callback of Array.from(this.callbacks)) {
|
||||
result.push(callback())
|
||||
}
|
||||
return result
|
||||
})()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,81 +11,126 @@
|
|||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let DocstoreClient;
|
||||
const request = require("request").defaults({jar: false});
|
||||
const {db, ObjectId} = require("../../../../app/js/mongojs");
|
||||
const settings = require("settings-sharelatex");
|
||||
const DocArchiveManager = require("../../../../app/js/DocArchiveManager.js");
|
||||
let DocstoreClient
|
||||
const request = require('request').defaults({ jar: false })
|
||||
const { db, ObjectId } = require('../../../../app/js/mongojs')
|
||||
const settings = require('settings-sharelatex')
|
||||
const DocArchiveManager = require('../../../../app/js/DocArchiveManager.js')
|
||||
|
||||
module.exports = (DocstoreClient = {
|
||||
module.exports = DocstoreClient = {
|
||||
createDoc(project_id, doc_id, lines, version, ranges, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error) {}
|
||||
}
|
||||
return DocstoreClient.updateDoc(
|
||||
project_id,
|
||||
doc_id,
|
||||
lines,
|
||||
version,
|
||||
ranges,
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
createDoc(project_id, doc_id, lines, version, ranges, callback) {
|
||||
if (callback == null) { callback = function(error) {}; }
|
||||
return DocstoreClient.updateDoc(project_id, doc_id, lines, version, ranges, callback);
|
||||
},
|
||||
getDoc(project_id, doc_id, qs, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.get(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
||||
json: true,
|
||||
qs
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
getDoc(project_id, doc_id, qs, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.get({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
||||
json: true,
|
||||
qs
|
||||
}, callback);
|
||||
},
|
||||
getAllDocs(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.get(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
|
||||
json: true
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
getAllDocs(project_id, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.get({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
|
||||
json: true
|
||||
}, callback);
|
||||
},
|
||||
getAllRanges(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.get(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
|
||||
json: true
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
getAllRanges(project_id, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.get({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
|
||||
json: true
|
||||
}, callback);
|
||||
},
|
||||
updateDoc(project_id, doc_id, lines, version, ranges, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.post(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
||||
json: {
|
||||
lines,
|
||||
version,
|
||||
ranges
|
||||
}
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
updateDoc(project_id, doc_id, lines, version, ranges, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.post({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
||||
json: {
|
||||
lines,
|
||||
version,
|
||||
ranges
|
||||
}
|
||||
}, callback);
|
||||
},
|
||||
deleteDoc(project_id, doc_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.del(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
deleteDoc(project_id, doc_id, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.del({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`
|
||||
}, callback);
|
||||
},
|
||||
|
||||
archiveAllDoc(project_id, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.post({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`
|
||||
}, callback);
|
||||
},
|
||||
archiveAllDoc(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.post(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
destroyAllDoc(project_id, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
return request.post({
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`
|
||||
}, callback);
|
||||
},
|
||||
destroyAllDoc(project_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
return request.post(
|
||||
{
|
||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`
|
||||
},
|
||||
callback
|
||||
)
|
||||
},
|
||||
|
||||
getS3Doc(project_id, doc_id, callback) {
|
||||
if (callback == null) { callback = function(error, res, body) {}; }
|
||||
const options = DocArchiveManager.buildS3Options(project_id+"/"+doc_id);
|
||||
options.json = true;
|
||||
return request.get(options, callback);
|
||||
}
|
||||
});
|
||||
getS3Doc(project_id, doc_id, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, res, body) {}
|
||||
}
|
||||
const options = DocArchiveManager.buildS3Options(project_id + '/' + doc_id)
|
||||
options.json = true
|
||||
return request.get(options, callback)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue