2014-03-25 07:40:48 -04:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
mongojs = require "../../../app/js/mongojs"
|
|
|
|
ObjectId = mongojs.ObjectId
|
|
|
|
Settings = require "settings-sharelatex"
|
|
|
|
request = require "request"
|
|
|
|
rclient = require("redis").createClient() # Only works locally for now
|
|
|
|
|
|
|
|
TrackChangesClient = require "./helpers/TrackChangesClient"
|
2014-03-28 12:01:34 -04:00
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
2014-03-25 07:40:48 -04:00
|
|
|
|
|
|
|
describe "Flushing updates", ->
|
|
|
|
describe "flushing a doc's updates", ->
|
|
|
|
before (done) ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
2014-05-16 10:59:12 -04:00
|
|
|
MockWebApi.projects[@project_id] = features: versioning: true
|
2014-03-28 12:01:34 -04:00
|
|
|
|
2014-03-25 07:40:48 -04:00
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, [{
|
|
|
|
op: [{ i: "f", p: 3 }]
|
|
|
|
meta: { ts: Date.now(), user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}], (error) =>
|
|
|
|
throw error if error?
|
|
|
|
TrackChangesClient.flushDoc @project_id, @doc_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should flush the op into mongo", (done) ->
|
|
|
|
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
2016-01-15 10:02:34 -05:00
|
|
|
expect(updates[0].pack[0].op).to.deep.equal [{
|
2014-03-25 07:40:48 -04:00
|
|
|
p: 3, i: "f"
|
|
|
|
}]
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "flushing a project's updates", ->
|
2014-03-28 12:01:34 -04:00
|
|
|
describe "with versioning enabled", ->
|
|
|
|
before (done) ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
|
|
|
|
@weeks = 7 * 24 * 60 * 60 * 1000
|
|
|
|
|
|
|
|
MockWebApi.projects[@project_id] =
|
|
|
|
features:
|
|
|
|
versioning: true
|
|
|
|
|
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, [{
|
|
|
|
op: [{ i: "g", p: 2 }]
|
|
|
|
meta: { ts: Date.now() - 2 * @weeks, user_id: @user_id }
|
|
|
|
v: 2
|
|
|
|
}, {
|
|
|
|
op: [{ i: "f", p: 3 }]
|
|
|
|
meta: { ts: Date.now(), user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}], (error) =>
|
2014-03-25 07:40:48 -04:00
|
|
|
throw error if error?
|
2014-03-28 12:01:34 -04:00
|
|
|
TrackChangesClient.flushProject @project_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
2014-05-29 10:37:16 -04:00
|
|
|
it "should not mark the updates for deletion", (done) ->
|
2014-03-28 12:01:34 -04:00
|
|
|
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
2014-05-29 10:37:16 -04:00
|
|
|
expect(updates[0].expiresAt).to.not.exist
|
2014-03-25 07:40:48 -04:00
|
|
|
done()
|
|
|
|
|
2014-03-28 12:01:34 -04:00
|
|
|
it "should preserve history forever", (done) ->
|
|
|
|
TrackChangesClient.getProjectMetaData @project_id, (error, project) ->
|
|
|
|
expect(project.preserveHistory).to.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "without versioning enabled", ->
|
|
|
|
before (done) ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
|
|
|
|
@weeks = 7 * 24 * 60 * 60 * 1000
|
|
|
|
|
|
|
|
MockWebApi.projects[@project_id] =
|
|
|
|
features:
|
|
|
|
versioning: false
|
|
|
|
|
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, [{
|
|
|
|
op: [{ i: "g", p: 2 }]
|
|
|
|
meta: { ts: Date.now() - 2 * @weeks, user_id: @user_id }
|
|
|
|
v: 2
|
|
|
|
}, {
|
|
|
|
op: [{ i: "f", p: 3 }]
|
|
|
|
meta: { ts: Date.now(), user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}], (error) =>
|
|
|
|
throw error if error?
|
|
|
|
TrackChangesClient.flushProject @project_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
2014-05-29 10:37:16 -04:00
|
|
|
it "should mark the updates for deletion", (done) ->
|
2014-03-28 12:01:34 -04:00
|
|
|
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
2014-05-29 10:37:16 -04:00
|
|
|
expect(updates[0].expiresAt).to.exist
|
2014-03-28 12:01:34 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
describe "without versioning enabled but with preserveHistory set to true", ->
|
|
|
|
before (done) ->
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
|
|
|
|
@weeks = 7 * 24 * 60 * 60 * 1000
|
|
|
|
|
|
|
|
MockWebApi.projects[@project_id] =
|
|
|
|
features:
|
|
|
|
versioning: false
|
|
|
|
|
|
|
|
TrackChangesClient.setPreserveHistoryForProject @project_id, (error) =>
|
|
|
|
throw error if error?
|
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, [{
|
|
|
|
op: [{ i: "g", p: 2 }]
|
|
|
|
meta: { ts: Date.now() - 2 * @weeks, user_id: @user_id }
|
|
|
|
v: 2
|
|
|
|
}, {
|
|
|
|
op: [{ i: "f", p: 3 }]
|
|
|
|
meta: { ts: Date.now(), user_id: @user_id }
|
|
|
|
v: 3
|
|
|
|
}], (error) =>
|
|
|
|
throw error if error?
|
|
|
|
TrackChangesClient.flushProject @project_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
2014-05-29 10:37:16 -04:00
|
|
|
it "should not mark the updates for deletion", (done) ->
|
2014-03-28 12:01:34 -04:00
|
|
|
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
2014-05-29 10:37:16 -04:00
|
|
|
expect(updates[0].expiresAt).to.not.exist
|
2014-03-28 12:01:34 -04:00
|
|
|
done()
|