|
@@ -21,13 +21,9 @@ const { assert } = require('chai')
|
|
|
|
|
|
|
|
describe('MongoManager', function () {
|
|
describe('MongoManager', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.db = {}
|
|
|
|
|
this.MongoManager = SandboxedModule.require(modulePath, {
|
|
this.MongoManager = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
requires: {
|
|
|
'./mongodb': {
|
|
'./mongodb': {
|
|
|
- getCollection: sinon.stub().callsFake((name) => {
|
|
|
|
|
- return Promise.resolve((this.db[name] = {}))
|
|
|
|
|
- }),
|
|
|
|
|
db: (this.db = { docs: {}, docOps: {} }),
|
|
db: (this.db = { docs: {}, docOps: {} }),
|
|
|
ObjectId
|
|
ObjectId
|
|
|
},
|
|
},
|
|
@@ -40,12 +36,12 @@ describe('MongoManager', function () {
|
|
|
})
|
|
})
|
|
|
this.project_id = ObjectId().toString()
|
|
this.project_id = ObjectId().toString()
|
|
|
this.doc_id = ObjectId().toString()
|
|
this.doc_id = ObjectId().toString()
|
|
|
|
|
+ this.callback = sinon.stub()
|
|
|
return (this.stubbedErr = new Error('hello world'))
|
|
return (this.stubbedErr = new Error('hello world'))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('findDoc', function () {
|
|
describe('findDoc', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(() => done())
|
|
|
|
|
|
|
+ beforeEach(function () {
|
|
|
this.doc = { name: 'mock-doc' }
|
|
this.doc = { name: 'mock-doc' }
|
|
|
this.db.docs.findOne = sinon.stub().callsArgWith(2, null, this.doc)
|
|
this.db.docs.findOne = sinon.stub().callsArgWith(2, null, this.doc)
|
|
|
this.filter = { lines: true }
|
|
this.filter = { lines: true }
|
|
@@ -89,8 +85,7 @@ describe('MongoManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('with included_deleted = false', function () {
|
|
describe('with included_deleted = false', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(() => done())
|
|
|
|
|
|
|
+ beforeEach(function () {
|
|
|
return this.MongoManager.getProjectsDocs(
|
|
return this.MongoManager.getProjectsDocs(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
{ include_deleted: false },
|
|
{ include_deleted: false },
|
|
@@ -119,8 +114,7 @@ describe('MongoManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
return describe('with included_deleted = true', function () {
|
|
return describe('with included_deleted = true', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(() => done())
|
|
|
|
|
|
|
+ beforeEach(function () {
|
|
|
return this.MongoManager.getProjectsDocs(
|
|
return this.MongoManager.getProjectsDocs(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
{ include_deleted: true },
|
|
{ include_deleted: true },
|
|
@@ -239,8 +233,7 @@ describe('MongoManager', function () {
|
|
|
|
|
|
|
|
describe('getDocVersion', function () {
|
|
describe('getDocVersion', function () {
|
|
|
describe('when the doc exists', function () {
|
|
describe('when the doc exists', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(() => done())
|
|
|
|
|
|
|
+ beforeEach(function () {
|
|
|
this.doc = { version: (this.version = 42) }
|
|
this.doc = { version: (this.version = 42) }
|
|
|
this.db.docOps.findOne = sinon.stub().callsArgWith(2, null, this.doc)
|
|
this.db.docOps.findOne = sinon.stub().callsArgWith(2, null, this.doc)
|
|
|
return this.MongoManager.getDocVersion(this.doc_id, this.callback)
|
|
return this.MongoManager.getDocVersion(this.doc_id, this.callback)
|
|
@@ -258,8 +251,7 @@ describe('MongoManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
return describe("when the doc doesn't exist", function () {
|
|
return describe("when the doc doesn't exist", function () {
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(() => done())
|
|
|
|
|
|
|
+ beforeEach(function () {
|
|
|
this.db.docOps.findOne = sinon.stub().callsArgWith(2, null, null)
|
|
this.db.docOps.findOne = sinon.stub().callsArgWith(2, null, null)
|
|
|
return this.MongoManager.getDocVersion(this.doc_id, this.callback)
|
|
return this.MongoManager.getDocVersion(this.doc_id, this.callback)
|
|
|
})
|
|
})
|
|
@@ -271,8 +263,7 @@ describe('MongoManager', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
return describe('setDocVersion', function () {
|
|
return describe('setDocVersion', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
|
|
- this.callback = sinon.stub().callsFake(() => done())
|
|
|
|
|
|
|
+ beforeEach(function () {
|
|
|
this.version = 42
|
|
this.version = 42
|
|
|
this.db.docOps.updateOne = sinon.stub().callsArg(3)
|
|
this.db.docOps.updateOne = sinon.stub().callsArg(3)
|
|
|
return this.MongoManager.setDocVersion(
|
|
return this.MongoManager.setDocVersion(
|