2014-02-24 12:43:27 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../../app/js/MongoManager.js"
|
2015-06-05 05:59:09 -04:00
|
|
|
packModulePath = "../../../../app/js/PackManager.js"
|
2014-02-24 12:43:27 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
{ObjectId} = require("mongojs")
|
2014-05-16 10:59:12 -04:00
|
|
|
tk = require "timekeeper"
|
2014-02-24 12:43:27 -05:00
|
|
|
|
|
|
|
describe "MongoManager", ->
|
|
|
|
beforeEach ->
|
2014-05-16 10:59:12 -04:00
|
|
|
tk.freeze(new Date())
|
2014-02-24 12:43:27 -05:00
|
|
|
@MongoManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"./mongojs" : { db: @db = {}, ObjectId: ObjectId }
|
2015-06-05 05:59:09 -04:00
|
|
|
"./PackManager" : SandboxedModule.require packModulePath, requires:
|
|
|
|
"./LockManager" : {}
|
2015-09-25 08:46:20 -04:00
|
|
|
"./mongojs": {db: bson: BSON = sinon.stub(), ObjectId}
|
|
|
|
"logger-sharelatex": {}
|
2014-02-24 12:43:27 -05:00
|
|
|
@callback = sinon.stub()
|
|
|
|
@doc_id = ObjectId().toString()
|
2014-03-19 12:40:55 -04:00
|
|
|
@project_id = ObjectId().toString()
|
2014-02-24 12:43:27 -05:00
|
|
|
|
2014-05-16 10:59:12 -04:00
|
|
|
afterEach ->
|
|
|
|
tk.reset()
|
|
|
|
|
2014-02-24 12:43:27 -05:00
|
|
|
describe "getLastCompressedUpdate", ->
|
|
|
|
beforeEach ->
|
|
|
|
@update = "mock-update"
|
|
|
|
@db.docHistory = {}
|
|
|
|
@db.docHistory.find = sinon.stub().returns @db.docHistory
|
|
|
|
@db.docHistory.sort = sinon.stub().returns @db.docHistory
|
|
|
|
@db.docHistory.limit = sinon.stub().returns @db.docHistory
|
|
|
|
@db.docHistory.toArray = sinon.stub().callsArgWith(0, null, [@update])
|
|
|
|
|
|
|
|
@MongoManager.getLastCompressedUpdate @doc_id, @callback
|
|
|
|
|
|
|
|
it "should find the updates for the doc", ->
|
|
|
|
@db.docHistory.find
|
|
|
|
.calledWith(doc_id: ObjectId(@doc_id))
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should limit to one result", ->
|
|
|
|
@db.docHistory.limit
|
|
|
|
.calledWith(1)
|
|
|
|
.should.equal true
|
|
|
|
|
2014-03-07 09:02:16 -05:00
|
|
|
it "should sort in descending version order", ->
|
2014-02-24 12:43:27 -05:00
|
|
|
@db.docHistory.sort
|
2014-03-07 09:02:16 -05:00
|
|
|
.calledWith(v: -1)
|
2014-02-24 12:43:27 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the call back with the update", ->
|
|
|
|
@callback.calledWith(null, @update).should.equal true
|
|
|
|
|
|
|
|
|
2015-10-08 11:10:48 -04:00
|
|
|
describe "peekLastCompressedUpdate", ->
|
2014-02-24 12:43:27 -05:00
|
|
|
describe "when there is no last update", ->
|
|
|
|
beforeEach ->
|
2016-01-15 10:02:09 -05:00
|
|
|
@db.docHistoryStats = {}
|
|
|
|
@db.docHistoryStats.findOne = sinon.stub().callsArgWith(2, null, null)
|
2014-02-24 12:43:27 -05:00
|
|
|
@MongoManager.getLastCompressedUpdate = sinon.stub().callsArgWith(1, null, null)
|
2015-10-08 11:10:48 -04:00
|
|
|
@MongoManager.peekLastCompressedUpdate @doc_id, @callback
|
2014-02-24 12:43:27 -05:00
|
|
|
|
|
|
|
it "should get the last update", ->
|
|
|
|
@MongoManager.getLastCompressedUpdate
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with no update", ->
|
|
|
|
@callback.calledWith(null, null).should.equal true
|
|
|
|
|
|
|
|
describe "when there is an update", ->
|
|
|
|
beforeEach ->
|
|
|
|
@update = { _id: Object() }
|
|
|
|
@MongoManager.getLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @update)
|
2015-10-08 11:10:48 -04:00
|
|
|
@MongoManager.peekLastCompressedUpdate @doc_id, @callback
|
2014-02-24 12:43:27 -05:00
|
|
|
|
|
|
|
it "should get the last update", ->
|
|
|
|
@MongoManager.getLastCompressedUpdate
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the update", ->
|
|
|
|
@callback.calledWith(null, @update).should.equal true
|
|
|
|
|
2015-09-23 08:22:38 -04:00
|
|
|
describe "when there is a last update in S3", ->
|
|
|
|
beforeEach ->
|
2016-01-15 10:02:09 -05:00
|
|
|
@update = { _id: Object(), v: 12345}
|
|
|
|
@db.docHistoryStats = {}
|
|
|
|
@db.docHistoryStats.findOne = sinon.stub().callsArgWith(2, null, {inS3:true, lastVersion: @update.v})
|
|
|
|
@MongoManager.getLastCompressedUpdate = sinon.stub().callsArgWith(1, null)
|
2015-10-08 11:10:48 -04:00
|
|
|
@MongoManager.peekLastCompressedUpdate @doc_id, @callback
|
2015-09-23 08:22:38 -04:00
|
|
|
|
|
|
|
it "should get the last update", ->
|
|
|
|
@MongoManager.getLastCompressedUpdate
|
|
|
|
.calledWith(@doc_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with a null update and the correct version", ->
|
|
|
|
@callback.calledWith(null, null, @update.v).should.equal true
|
|
|
|
|
|
|
|
|
2014-02-24 12:43:27 -05:00
|
|
|
describe "insertCompressedUpdate", ->
|
|
|
|
beforeEach ->
|
|
|
|
@update = { op: "op", meta: "meta", v: "v"}
|
|
|
|
@db.docHistory =
|
|
|
|
insert: sinon.stub().callsArg(1)
|
|
|
|
|
2014-05-16 10:59:12 -04:00
|
|
|
describe "temporarly", ->
|
|
|
|
beforeEach ->
|
|
|
|
@MongoManager.insertCompressedUpdate @project_id, @doc_id, @update, true, @callback
|
|
|
|
|
2014-05-16 11:41:14 -04:00
|
|
|
it "should insert the update with a expiresAt field one week away", ->
|
2014-05-16 10:59:12 -04:00
|
|
|
@db.docHistory.insert
|
|
|
|
.calledWith({
|
|
|
|
project_id: ObjectId(@project_id),
|
|
|
|
doc_id: ObjectId(@doc_id),
|
|
|
|
op: @update.op,
|
|
|
|
meta: @update.meta,
|
|
|
|
v: @update.v
|
2014-05-16 11:41:14 -04:00
|
|
|
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
|
2014-05-16 10:59:12 -04:00
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "permanenty", ->
|
|
|
|
beforeEach ->
|
|
|
|
@MongoManager.insertCompressedUpdate @project_id, @doc_id, @update, false, @callback
|
|
|
|
|
2014-05-16 11:41:14 -04:00
|
|
|
it "should insert the update with no expiresAt field", ->
|
2014-05-16 10:59:12 -04:00
|
|
|
@db.docHistory.insert
|
|
|
|
.calledWith({
|
|
|
|
project_id: ObjectId(@project_id),
|
|
|
|
doc_id: ObjectId(@doc_id),
|
|
|
|
op: @update.op,
|
|
|
|
meta: @update.meta,
|
|
|
|
v: @update.v
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2014-02-24 12:43:27 -05:00
|
|
|
|
|
|
|
describe "insertCompressedUpdates", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@updates = [ "mock-update-1", "mock-update-2" ]
|
2014-05-16 10:59:12 -04:00
|
|
|
@MongoManager.insertCompressedUpdate = sinon.stub().callsArg(4)
|
|
|
|
@MongoManager.insertCompressedUpdates @project_id, @doc_id, @updates, @temporary = true, (args...) =>
|
2014-02-24 12:43:27 -05:00
|
|
|
@callback(args...)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should insert each update", ->
|
|
|
|
for update in @updates
|
|
|
|
@MongoManager.insertCompressedUpdate
|
2014-05-16 10:59:12 -04:00
|
|
|
.calledWith(@project_id, @doc_id, update, @temporary)
|
2014-02-24 12:43:27 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2014-03-04 08:02:48 -05:00
|
|
|
|
2014-03-19 13:44:16 -04:00
|
|
|
describe "getDocUpdates", ->
|
2014-03-04 08:02:48 -05:00
|
|
|
beforeEach ->
|
2015-02-16 10:38:40 -05:00
|
|
|
@results = [
|
2015-02-16 10:59:58 -05:00
|
|
|
{foo: "mock-update", v: 56, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 55, doc_id: 100, project_id: 1},
|
|
|
|
{pack: [ {foo: "mock-update", v: 54, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, doc_id: 100, project_id: 1} ]
|
|
|
|
, v: 52, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 42, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 41, doc_id: 100, project_id: 1}
|
2015-02-16 10:38:40 -05:00
|
|
|
]
|
|
|
|
@updates_between = [
|
2015-02-16 10:59:58 -05:00
|
|
|
{foo: "mock-update", v: 55, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 54, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 42, doc_id: 100, project_id: 1}
|
2015-02-16 10:38:40 -05:00
|
|
|
]
|
|
|
|
@updates_after = [
|
2015-02-16 10:59:58 -05:00
|
|
|
{foo: "mock-update", v: 56, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 55, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 54, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 42, doc_id: 100, project_id: 1}
|
2015-02-16 10:38:40 -05:00
|
|
|
]
|
2014-03-04 08:02:48 -05:00
|
|
|
@db.docHistory = {}
|
|
|
|
@db.docHistory.find = sinon.stub().returns @db.docHistory
|
|
|
|
@db.docHistory.sort = sinon.stub().returns @db.docHistory
|
2014-03-05 10:59:40 -05:00
|
|
|
@db.docHistory.limit = sinon.stub().returns @db.docHistory
|
2015-02-16 10:38:40 -05:00
|
|
|
@db.docHistory.toArray = sinon.stub().callsArgWith(0, null, @results)
|
2014-03-04 08:02:48 -05:00
|
|
|
|
2014-03-06 05:45:51 -05:00
|
|
|
@from = 42
|
|
|
|
@to = 55
|
2014-03-04 08:02:48 -05:00
|
|
|
|
2014-03-06 05:45:51 -05:00
|
|
|
describe "with a to version", ->
|
2014-03-04 09:05:17 -05:00
|
|
|
beforeEach ->
|
2014-03-19 13:44:16 -04:00
|
|
|
@MongoManager.getDocUpdates @doc_id, from: @from, to: @to, @callback
|
2014-03-04 09:05:17 -05:00
|
|
|
|
2014-03-06 05:45:51 -05:00
|
|
|
it "should find the all updates between the to and from versions", ->
|
2014-03-04 09:05:17 -05:00
|
|
|
@db.docHistory.find
|
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
2014-03-06 05:45:51 -05:00
|
|
|
v: { $gte: @from, $lte: @to }
|
2014-03-04 09:05:17 -05:00
|
|
|
})
|
|
|
|
.should.equal true
|
2014-03-04 08:02:48 -05:00
|
|
|
|
2014-03-06 05:45:51 -05:00
|
|
|
it "should sort in descending version order", ->
|
2014-03-04 09:05:17 -05:00
|
|
|
@db.docHistory.sort
|
2014-03-06 05:45:51 -05:00
|
|
|
.calledWith("v": -1)
|
2014-03-04 09:05:17 -05:00
|
|
|
.should.equal true
|
2014-03-04 08:02:48 -05:00
|
|
|
|
2015-02-16 10:38:40 -05:00
|
|
|
#it "should not limit the results", ->
|
|
|
|
# @db.docHistory.limit
|
|
|
|
# .called.should.equal false
|
2014-03-05 10:59:40 -05:00
|
|
|
|
2015-02-16 10:38:40 -05:00
|
|
|
it "should call the call back with the results", ->
|
|
|
|
@callback.calledWith(null, @updates_between).should.equal true
|
2014-03-04 09:05:17 -05:00
|
|
|
|
2014-03-06 05:45:51 -05:00
|
|
|
describe "without a to version", ->
|
2014-03-04 09:05:17 -05:00
|
|
|
beforeEach ->
|
2014-03-19 13:44:16 -04:00
|
|
|
@MongoManager.getDocUpdates @doc_id, from: @from, @callback
|
2014-03-04 09:05:17 -05:00
|
|
|
|
2014-03-06 05:45:51 -05:00
|
|
|
it "should find the all updates after the from version", ->
|
2014-03-04 09:05:17 -05:00
|
|
|
@db.docHistory.find
|
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
2014-03-06 05:45:51 -05:00
|
|
|
v: { $gte: @from }
|
2014-03-04 09:05:17 -05:00
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the call back with the updates", ->
|
2015-02-16 10:38:40 -05:00
|
|
|
@callback.calledWith(null, @updates_after).should.equal true
|
2014-03-04 08:02:48 -05:00
|
|
|
|
2014-03-05 10:59:40 -05:00
|
|
|
describe "with a limit", ->
|
|
|
|
beforeEach ->
|
2014-03-19 13:44:16 -04:00
|
|
|
@MongoManager.getDocUpdates @doc_id, from: @from, limit: @limit = 10, @callback
|
2014-03-05 10:59:40 -05:00
|
|
|
|
|
|
|
it "should limit the results", ->
|
|
|
|
@db.docHistory.limit
|
|
|
|
.calledWith(@limit)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
|
2014-03-19 13:44:16 -04:00
|
|
|
describe "getDocUpdates", ->
|
|
|
|
beforeEach ->
|
2015-02-16 10:38:40 -05:00
|
|
|
@results = [
|
2015-02-16 11:43:27 -05:00
|
|
|
{foo: "mock-update", v: 56, meta: {end_ts: 110}, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 55, meta: {end_ts: 100}, doc_id: 100, project_id: 1},
|
|
|
|
{pack: [
|
|
|
|
{foo: "mock-update", v: 54, meta: {end_ts: 99}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, meta: {end_ts: 98}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, meta: {end_ts: 97}, doc_id: 300, project_id: 1} ]
|
|
|
|
, v: 52, meta: {end_ts: 100}, doc_id: 300, project_id: 1},
|
|
|
|
{pack: [
|
|
|
|
{foo: "mock-update", v: 54, meta: {end_ts: 103}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, meta: {end_ts: 101}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, meta: {end_ts: 99}, doc_id: 200, project_id: 1} ]
|
|
|
|
, v: 52, meta: {end_ts: 103}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 42, meta:{end_ts: 90}, doc_id: 100, project_id: 1}
|
2015-02-16 10:38:40 -05:00
|
|
|
]
|
2015-02-16 11:43:27 -05:00
|
|
|
@updates_before = [
|
|
|
|
{foo: "mock-update", v: 55, meta: {end_ts: 100}, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, meta: {end_ts: 99}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 54, meta: {end_ts: 99}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, meta: {end_ts: 98}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, meta: {end_ts: 97}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 42, meta: {end_ts: 90}, doc_id: 100, project_id: 1},
|
2015-02-16 10:38:40 -05:00
|
|
|
]
|
2015-02-16 11:43:27 -05:00
|
|
|
@updates_all = [
|
|
|
|
{foo: "mock-update", v: 56, meta: {end_ts: 110}, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 54, meta: {end_ts: 103}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, meta: {end_ts: 101}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 55, meta: {end_ts: 100}, doc_id: 100, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, meta: {end_ts: 99}, doc_id: 200, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 54, meta: {end_ts: 99}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 53, meta: {end_ts: 98}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 52, meta: {end_ts: 97}, doc_id: 300, project_id: 1},
|
|
|
|
{foo: "mock-update", v: 42, meta: {end_ts: 90}, doc_id: 100, project_id: 1}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2014-03-19 13:44:16 -04:00
|
|
|
@db.docHistory = {}
|
|
|
|
@db.docHistory.find = sinon.stub().returns @db.docHistory
|
|
|
|
@db.docHistory.sort = sinon.stub().returns @db.docHistory
|
|
|
|
@db.docHistory.limit = sinon.stub().returns @db.docHistory
|
2015-02-16 10:38:40 -05:00
|
|
|
@db.docHistory.toArray = sinon.stub().callsArgWith(0, null, @results)
|
2014-03-19 13:44:16 -04:00
|
|
|
|
2015-02-16 10:38:40 -05:00
|
|
|
@before = 101
|
2014-03-19 13:44:16 -04:00
|
|
|
|
|
|
|
describe "with a before timestamp", ->
|
|
|
|
beforeEach ->
|
|
|
|
@MongoManager.getProjectUpdates @project_id, before: @before, @callback
|
|
|
|
|
|
|
|
it "should find the all updates before the timestamp", ->
|
|
|
|
@db.docHistory.find
|
|
|
|
.calledWith({
|
|
|
|
project_id: ObjectId(@project_id)
|
|
|
|
"meta.end_ts": { $lt: @before }
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should sort in descending version order", ->
|
|
|
|
@db.docHistory.sort
|
|
|
|
.calledWith("meta.end_ts": -1)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should not limit the results", ->
|
|
|
|
@db.docHistory.limit
|
|
|
|
.called.should.equal false
|
|
|
|
|
|
|
|
it "should call the call back with the updates", ->
|
2015-02-16 11:43:27 -05:00
|
|
|
@callback.calledWith(null, @updates_before).should.equal true
|
2014-03-19 13:44:16 -04:00
|
|
|
|
|
|
|
describe "without a before timestamp", ->
|
|
|
|
beforeEach ->
|
|
|
|
@MongoManager.getProjectUpdates @project_id, {}, @callback
|
|
|
|
|
|
|
|
it "should find the all updates", ->
|
|
|
|
@db.docHistory.find
|
|
|
|
.calledWith({
|
|
|
|
project_id: ObjectId(@project_id)
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the call back with the updates", ->
|
2015-02-16 11:43:27 -05:00
|
|
|
@callback.calledWith(null, @updates_all).should.equal true
|
2014-03-19 13:44:16 -04:00
|
|
|
|
|
|
|
describe "with a limit", ->
|
|
|
|
beforeEach ->
|
|
|
|
@MongoManager.getProjectUpdates @project_id, before: @before, limit: @limit = 10, @callback
|
|
|
|
|
|
|
|
it "should limit the results", ->
|
|
|
|
@db.docHistory.limit
|
|
|
|
.calledWith(@limit)
|
|
|
|
.should.equal true
|
2014-03-21 10:40:51 -04:00
|
|
|
|
|
|
|
describe "backportProjectId", ->
|
|
|
|
beforeEach ->
|
|
|
|
@db.docHistory =
|
|
|
|
update: sinon.stub().callsArg(3)
|
|
|
|
@MongoManager.backportProjectId @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should insert the project_id into all entries for the doc_id which don't have it set", ->
|
|
|
|
@db.docHistory.update
|
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
|
|
|
project_id: { $exists: false }
|
|
|
|
}, {
|
|
|
|
$set: { project_id: ObjectId(@project_id) }
|
|
|
|
}, {
|
|
|
|
multi: true
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
2014-03-28 12:01:34 -04:00
|
|
|
describe "getProjectMetaData", ->
|
|
|
|
beforeEach ->
|
|
|
|
@metadata = { "mock": "metadata" }
|
|
|
|
@db.projectHistoryMetaData =
|
|
|
|
find: sinon.stub().callsArgWith(1, null, [@metadata])
|
|
|
|
@MongoManager.getProjectMetaData @project_id, @callback
|
|
|
|
|
|
|
|
it "should look up the meta data in the db", ->
|
|
|
|
@db.projectHistoryMetaData.find
|
|
|
|
.calledWith({ project_id: ObjectId(@project_id) })
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should return the metadata", ->
|
|
|
|
@callback.calledWith(null, @metadata).should.equal true
|
|
|
|
|
|
|
|
describe "setProjectMetaData", ->
|
|
|
|
beforeEach ->
|
|
|
|
@metadata = { "mock": "metadata" }
|
|
|
|
@db.projectHistoryMetaData =
|
|
|
|
update: sinon.stub().callsArgWith(3, null, [@metadata])
|
|
|
|
@MongoManager.setProjectMetaData @project_id, @metadata, @callback
|
|
|
|
|
|
|
|
it "should upsert the metadata into the DB", ->
|
|
|
|
@db.projectHistoryMetaData.update
|
|
|
|
.calledWith({
|
|
|
|
project_id: ObjectId(@project_id)
|
|
|
|
}, {
|
|
|
|
$set: @metadata
|
|
|
|
}, {
|
|
|
|
upsert: true
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2015-08-31 17:13:18 -04:00
|
|
|
|
|
|
|
describe "getDocChangesCount", ->
|
|
|
|
beforeEach ->
|
|
|
|
@db.docHistory =
|
2015-12-22 09:03:35 -05:00
|
|
|
count: sinon.stub().callsArg(1)
|
2015-08-31 17:13:18 -04:00
|
|
|
@MongoManager.getDocChangesCount @doc_id, @callback
|
|
|
|
|
|
|
|
it "should return if there is any doc changes", ->
|
|
|
|
@db.docHistory.count
|
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
2016-01-15 10:49:07 -05:00
|
|
|
describe "getArchivedDocStatus", ->
|
2015-08-31 17:13:18 -04:00
|
|
|
beforeEach ->
|
2016-01-15 10:49:07 -05:00
|
|
|
@db.docHistoryStats =
|
|
|
|
findOne: sinon.stub().callsArg(2)
|
|
|
|
@MongoManager.getArchivedDocStatus @doc_id, @callback
|
2015-08-31 17:13:18 -04:00
|
|
|
|
|
|
|
it "should return if there is any archived doc changes", ->
|
2016-01-15 10:49:07 -05:00
|
|
|
@db.docHistoryStats.findOne
|
2015-08-31 17:13:18 -04:00
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
2015-09-23 10:34:36 -04:00
|
|
|
inS3: {$exists: true}
|
2015-08-31 17:13:18 -04:00
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "markDocHistoryAsArchived", ->
|
|
|
|
beforeEach ->
|
|
|
|
@update = { _id: ObjectId(), op: "op", meta: "meta", v: "v"}
|
2016-01-15 10:49:07 -05:00
|
|
|
@db.docHistoryStats =
|
|
|
|
update: sinon.stub().callsArg(3)
|
2015-08-31 17:13:18 -04:00
|
|
|
@db.docHistory =
|
|
|
|
remove: sinon.stub().callsArg(1)
|
2016-01-15 10:49:07 -05:00
|
|
|
@MongoManager.markDocHistoryAsArchived @doc_id, @update.v, @callback
|
2015-08-31 17:13:18 -04:00
|
|
|
|
2016-01-15 10:49:07 -05:00
|
|
|
it "should update doc status with inS3 flag", ->
|
|
|
|
@db.docHistoryStats.update
|
2015-08-31 17:13:18 -04:00
|
|
|
.calledWith({
|
2016-01-15 10:49:07 -05:00
|
|
|
doc_id: ObjectId(@doc_id)
|
2015-08-31 17:13:18 -04:00
|
|
|
},{
|
|
|
|
$set : { inS3 : true }
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should remove any other doc changes before last update", ->
|
|
|
|
@db.docHistory.remove
|
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
2016-01-15 10:49:07 -05:00
|
|
|
v: { $lte : @update.v }
|
2015-08-31 17:13:18 -04:00
|
|
|
expiresAt: {$exists : false}
|
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "markDocHistoryAsUnarchived", ->
|
|
|
|
beforeEach ->
|
2016-01-15 10:49:07 -05:00
|
|
|
@db.docHistoryStats =
|
|
|
|
update: sinon.stub().callsArg(2)
|
2015-08-31 17:13:18 -04:00
|
|
|
@MongoManager.markDocHistoryAsUnarchived @doc_id, @callback
|
|
|
|
|
|
|
|
it "should remove any doc changes inS3 flag", ->
|
2016-01-15 10:49:07 -05:00
|
|
|
@db.docHistoryStats.update
|
2015-08-31 17:13:18 -04:00
|
|
|
.calledWith({
|
|
|
|
doc_id: ObjectId(@doc_id)
|
|
|
|
},{
|
2016-01-15 10:49:07 -05:00
|
|
|
$unset : { inS3 : true, lastVersion: true }
|
2015-08-31 17:13:18 -04:00
|
|
|
})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
2015-09-23 08:22:38 -04:00
|
|
|
@callback.called.should.equal true
|