| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- /* eslint-disable
- handle-callback-err,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * 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 { expect } = require('chai')
- const { ObjectId } = require('../../../app/js/mongodb')
- const Settings = require('@overleaf/settings')
- 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 () {
- before(function (done) {
- return TrackChangesApp.ensureRunning(done)
- })
- 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 },
- v: 3,
- },
- ],
- error => {
- if (error != null) {
- throw error
- }
- return TrackChangesClient.flushDoc(
- this.project_id,
- this.doc_id,
- error => {
- if (error != null) {
- throw error
- }
- return done()
- }
- )
- }
- )
- return null
- })
- return it('should flush the op into mongo', function (done) {
- TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => {
- expect(updates[0].pack[0].op).to.deep.equal([
- {
- p: 3,
- i: 'f',
- },
- ])
- 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: {
- versioning: true,
- },
- }
- 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 },
- v: 2,
- },
- {
- op: [{ i: 'f', p: 3 }],
- meta: { ts: Date.now(), user_id: this.user_id },
- v: 3,
- },
- ],
- error => {
- if (error != null) {
- throw error
- }
- return TrackChangesClient.flushProject(this.project_id, error => {
- if (error != null) {
- throw error
- }
- return done()
- })
- }
- )
- return null
- })
- it('should not mark the updates for deletion', function (done) {
- TrackChangesClient.getCompressedUpdates(
- this.doc_id,
- (error, updates) => {
- expect(updates[0].expiresAt).to.not.exist
- return done()
- }
- )
- return null
- })
- return it('should preserve history forever', function (done) {
- TrackChangesClient.getProjectMetaData(
- this.project_id,
- (error, project) => {
- 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: {
- versioning: false,
- },
- }
- 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 },
- v: 2,
- },
- {
- op: [{ i: 'f', p: 3 }],
- meta: { ts: Date.now(), user_id: this.user_id },
- v: 3,
- },
- ],
- error => {
- if (error != null) {
- throw error
- }
- return TrackChangesClient.flushProject(this.project_id, error => {
- if (error != null) {
- throw error
- }
- return done()
- })
- }
- )
- return null
- })
- return it('should mark the updates for deletion', function (done) {
- TrackChangesClient.getCompressedUpdates(
- this.doc_id,
- (error, updates) => {
- 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: {
- versioning: false,
- },
- }
- 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,
- },
- v: 2,
- },
- {
- op: [{ i: 'f', p: 3 }],
- meta: { ts: Date.now(), user_id: this.user_id },
- v: 3,
- },
- ],
- error => {
- if (error != null) {
- throw error
- }
- return TrackChangesClient.flushProject(
- this.project_id,
- error => {
- if (error != null) {
- throw error
- }
- return done()
- }
- )
- }
- )
- }
- )
- return null
- })
- return it('should not mark the updates for deletion', function (done) {
- TrackChangesClient.getCompressedUpdates(
- this.doc_id,
- (error, updates) => {
- expect(updates[0].expiresAt).to.not.exist
- return done()
- }
- )
- return null
- })
- })
- })
- })
|