2020-02-17 12:35:50 -05:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:35:39 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* 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 { expect } = chai;
|
|
|
|
const mongojs = require("../../../app/js/mongojs");
|
|
|
|
const { ObjectId } = mongojs;
|
|
|
|
const Settings = require("settings-sharelatex");
|
|
|
|
const request = require("request");
|
|
|
|
const rclient = require("redis").createClient(Settings.redis.history); // Only works locally for now
|
|
|
|
|
|
|
|
const TrackChangesApp = require("./helpers/TrackChangesApp");
|
|
|
|
const TrackChangesClient = require("./helpers/TrackChangesClient");
|
|
|
|
const MockWebApi = require("./helpers/MockWebApi");
|
|
|
|
|
|
|
|
describe("Flushing updates", function() {
|
2020-02-17 12:35:50 -05:00
|
|
|
before(function(done) { return TrackChangesApp.ensureRunning(done); });
|
2020-02-17 12:35:39 -05:00
|
|
|
|
|
|
|
describe("flushing a doc's updates", function() {
|
|
|
|
before(function(done) {
|
|
|
|
this.project_id = ObjectId().toString();
|
|
|
|
this.doc_id = ObjectId().toString();
|
|
|
|
this.user_id = ObjectId().toString();
|
|
|
|
MockWebApi.projects[this.project_id] = {features: {versioning: true}};
|
|
|
|
|
|
|
|
TrackChangesClient.pushRawUpdates(this.project_id, this.doc_id, [{
|
|
|
|
op: [{ i: "f", p: 3 }],
|
|
|
|
meta: { ts: Date.now(), user_id: this.user_id },
|
2014-03-25 07:40:48 -04:00
|
|
|
v: 3
|
2020-02-17 12:35:39 -05:00
|
|
|
}], error => {
|
|
|
|
if (error != null) { throw error; }
|
2020-02-17 12:35:50 -05:00
|
|
|
return TrackChangesClient.flushDoc(this.project_id, this.doc_id, (error) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (error != null) { throw error; }
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return it("should flush the op into mongo", function(done) {
|
2020-02-17 12:35:50 -05:00
|
|
|
TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
expect(updates[0].pack[0].op).to.deep.equal([{
|
2014-03-25 07:40:48 -04:00
|
|
|
p: 3, i: "f"
|
2020-02-17 12:35:39 -05:00
|
|
|
}]);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return describe("flushing a project's updates", function() {
|
|
|
|
describe("with versioning enabled", function() {
|
|
|
|
before(function(done) {
|
|
|
|
this.project_id = ObjectId().toString();
|
|
|
|
this.doc_id = ObjectId().toString();
|
|
|
|
this.user_id = ObjectId().toString();
|
|
|
|
|
|
|
|
this.weeks = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
MockWebApi.projects[this.project_id] = {
|
|
|
|
features: {
|
2014-03-28 12:01:34 -04:00
|
|
|
versioning: true
|
2020-02-17 12:35:39 -05:00
|
|
|
}
|
|
|
|
};
|
2014-03-28 12:01:34 -04:00
|
|
|
|
2020-02-17 12:35:39 -05:00
|
|
|
TrackChangesClient.pushRawUpdates(this.project_id, this.doc_id, [{
|
|
|
|
op: [{ i: "g", p: 2 }],
|
|
|
|
meta: { ts: Date.now() - (2 * this.weeks), user_id: this.user_id },
|
2014-03-28 12:01:34 -04:00
|
|
|
v: 2
|
|
|
|
}, {
|
2020-02-17 12:35:39 -05:00
|
|
|
op: [{ i: "f", p: 3 }],
|
|
|
|
meta: { ts: Date.now(), user_id: this.user_id },
|
2014-03-28 12:01:34 -04:00
|
|
|
v: 3
|
2020-02-17 12:35:39 -05:00
|
|
|
}], error => {
|
|
|
|
if (error != null) { throw error; }
|
2020-02-17 12:35:50 -05:00
|
|
|
return TrackChangesClient.flushProject(this.project_id, (error) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (error != null) { throw error; }
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not mark the updates for deletion", function(done) {
|
2020-02-17 12:35:50 -05:00
|
|
|
TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
expect(updates[0].expiresAt).to.not.exist;
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return it("should preserve history forever", function(done) {
|
2020-02-17 12:35:50 -05:00
|
|
|
TrackChangesClient.getProjectMetaData(this.project_id, (error, project) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
expect(project.preserveHistory).to.equal(true);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("without versioning enabled", function() {
|
|
|
|
before(function(done) {
|
|
|
|
this.project_id = ObjectId().toString();
|
|
|
|
this.doc_id = ObjectId().toString();
|
|
|
|
this.user_id = ObjectId().toString();
|
|
|
|
|
|
|
|
this.weeks = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
MockWebApi.projects[this.project_id] = {
|
|
|
|
features: {
|
2014-03-28 12:01:34 -04:00
|
|
|
versioning: false
|
2020-02-17 12:35:39 -05:00
|
|
|
}
|
|
|
|
};
|
2014-03-28 12:01:34 -04:00
|
|
|
|
2020-02-17 12:35:39 -05:00
|
|
|
TrackChangesClient.pushRawUpdates(this.project_id, this.doc_id, [{
|
|
|
|
op: [{ i: "g", p: 2 }],
|
|
|
|
meta: { ts: Date.now() - (2 * this.weeks), user_id: this.user_id },
|
2014-03-28 12:01:34 -04:00
|
|
|
v: 2
|
|
|
|
}, {
|
2020-02-17 12:35:39 -05:00
|
|
|
op: [{ i: "f", p: 3 }],
|
|
|
|
meta: { ts: Date.now(), user_id: this.user_id },
|
2014-03-28 12:01:34 -04:00
|
|
|
v: 3
|
2020-02-17 12:35:39 -05:00
|
|
|
}], error => {
|
|
|
|
if (error != null) { throw error; }
|
2020-02-17 12:35:50 -05:00
|
|
|
return TrackChangesClient.flushProject(this.project_id, (error) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (error != null) { throw error; }
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return it("should mark the updates for deletion", function(done) {
|
2020-02-17 12:35:50 -05:00
|
|
|
TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
expect(updates[0].expiresAt).to.exist;
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return describe("without versioning enabled but with preserveHistory set to true", function() {
|
|
|
|
before(function(done) {
|
|
|
|
this.project_id = ObjectId().toString();
|
|
|
|
this.doc_id = ObjectId().toString();
|
|
|
|
this.user_id = ObjectId().toString();
|
|
|
|
|
|
|
|
this.weeks = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
MockWebApi.projects[this.project_id] = {
|
|
|
|
features: {
|
2014-03-28 12:01:34 -04:00
|
|
|
versioning: false
|
2020-02-17 12:35:39 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TrackChangesClient.setPreserveHistoryForProject(this.project_id, error => {
|
|
|
|
if (error != null) { throw error; }
|
|
|
|
return TrackChangesClient.pushRawUpdates(this.project_id, this.doc_id, [{
|
|
|
|
op: [{ i: "g", p: 2 }],
|
|
|
|
meta: { ts: Date.now() - (2 * this.weeks), user_id: this.user_id },
|
2014-03-28 12:01:34 -04:00
|
|
|
v: 2
|
|
|
|
}, {
|
2020-02-17 12:35:39 -05:00
|
|
|
op: [{ i: "f", p: 3 }],
|
|
|
|
meta: { ts: Date.now(), user_id: this.user_id },
|
2014-03-28 12:01:34 -04:00
|
|
|
v: 3
|
2020-02-17 12:35:39 -05:00
|
|
|
}], error => {
|
|
|
|
if (error != null) { throw error; }
|
2020-02-17 12:35:50 -05:00
|
|
|
return TrackChangesClient.flushProject(this.project_id, (error) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
if (error != null) { throw error; }
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return it("should not mark the updates for deletion", function(done) {
|
2020-02-17 12:35:50 -05:00
|
|
|
TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => {
|
2020-02-17 12:35:39 -05:00
|
|
|
expect(updates[0].expiresAt).to.not.exist;
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|