2015-09-02 17:47:34 -04:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
mongojs = require "../../../app/js/mongojs"
|
|
|
|
db = mongojs.db
|
|
|
|
ObjectId = mongojs.ObjectId
|
|
|
|
Settings = require "settings-sharelatex"
|
|
|
|
request = require "request"
|
|
|
|
rclient = require("redis").createClient() # Only works locally for now
|
|
|
|
|
|
|
|
TrackChangesClient = require "./helpers/TrackChangesClient"
|
|
|
|
MockDocStoreApi = require "./helpers/MockDocStoreApi"
|
|
|
|
MockWebApi = require "./helpers/MockWebApi"
|
|
|
|
|
|
|
|
describe "Archiving updates", ->
|
|
|
|
before (done) ->
|
|
|
|
@now = Date.now()
|
|
|
|
@to = @now
|
|
|
|
@user_id = ObjectId().toString()
|
|
|
|
@doc_id = ObjectId().toString()
|
|
|
|
@project_id = ObjectId().toString()
|
|
|
|
|
|
|
|
@minutes = 60 * 1000
|
|
|
|
@hours = 60 * @minutes
|
|
|
|
|
|
|
|
MockWebApi.projects[@project_id] =
|
|
|
|
features:
|
|
|
|
versioning: true
|
2015-09-16 18:33:23 -04:00
|
|
|
sinon.spy MockWebApi, "getProjectDetails"
|
2015-09-02 17:47:34 -04:00
|
|
|
|
|
|
|
MockWebApi.users[@user_id] = @user =
|
|
|
|
email: "user@sharelatex.com"
|
|
|
|
first_name: "Leo"
|
|
|
|
last_name: "Lion"
|
|
|
|
id: @user_id
|
2015-09-16 18:33:23 -04:00
|
|
|
sinon.spy MockWebApi, "getUserInfo"
|
2015-09-02 17:47:34 -04:00
|
|
|
|
|
|
|
MockDocStoreApi.docs[@doc_id] = @doc =
|
|
|
|
_id: @doc_id
|
|
|
|
project_id: @project_id
|
|
|
|
sinon.spy MockDocStoreApi, "getAllDoc"
|
|
|
|
|
|
|
|
@updates = []
|
|
|
|
for i in [0..9]
|
|
|
|
@updates.push {
|
|
|
|
op: [{ i: "a", p: 0 }]
|
|
|
|
meta: { ts: @now - (9 - i) * @hours - 2 * @minutes, user_id: @user_id }
|
|
|
|
v: 2 * i + 1
|
|
|
|
}
|
|
|
|
@updates.push {
|
|
|
|
op: [{ i: "b", p: 0 }]
|
|
|
|
meta: { ts: @now - (9 - i) * @hours, user_id: @user_id }
|
|
|
|
v: 2 * i + 2
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackChangesClient.pushRawUpdates @project_id, @doc_id, @updates, (error) =>
|
|
|
|
throw error if error?
|
|
|
|
TrackChangesClient.flushDoc @project_id, @doc_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
2015-09-03 07:36:32 -04:00
|
|
|
after (done) ->
|
2015-09-16 18:33:23 -04:00
|
|
|
MockWebApi.getUserInfo.restore()
|
2016-01-05 07:10:57 -05:00
|
|
|
db.docHistory.remove {project_id: ObjectId(@project_id)}, () ->
|
|
|
|
TrackChangesClient.removeS3Doc @project_id, @doc_id, done
|
2015-09-02 17:47:34 -04:00
|
|
|
|
|
|
|
describe "archiving a doc's updates", ->
|
|
|
|
before (done) ->
|
|
|
|
TrackChangesClient.archiveProject @project_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
2016-01-15 10:49:07 -05:00
|
|
|
it "should remain zero doc change", (done) ->
|
2015-09-02 17:47:34 -04:00
|
|
|
db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
|
|
|
|
throw error if error?
|
2016-01-15 10:49:07 -05:00
|
|
|
count.should.equal 0
|
2015-09-02 17:47:34 -04:00
|
|
|
done()
|
|
|
|
|
2016-01-15 10:49:07 -05:00
|
|
|
it "should have docHistoryStats marked as inS3", (done) ->
|
|
|
|
db.docHistoryStats.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
|
2015-09-02 17:47:34 -04:00
|
|
|
throw error if error?
|
|
|
|
doc.inS3.should.equal true
|
|
|
|
done()
|
|
|
|
|
2016-01-15 10:49:07 -05:00
|
|
|
it "should have docHistoryStats with the last version", (done) ->
|
|
|
|
db.docHistoryStats.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
|
2015-09-02 17:47:34 -04:00
|
|
|
throw error if error?
|
2016-01-15 10:49:07 -05:00
|
|
|
doc.lastVersion.should.equal 20
|
2015-09-03 07:36:32 -04:00
|
|
|
done()
|
|
|
|
|
2016-01-15 10:49:07 -05:00
|
|
|
it "should store twenty doc changes in S3", (done) ->
|
2015-09-03 07:36:32 -04:00
|
|
|
TrackChangesClient.getS3Doc @project_id, @doc_id, (error, res, doc) =>
|
2016-01-15 10:49:07 -05:00
|
|
|
doc.length.should.equal 20
|
2015-09-03 07:36:32 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
describe "unarchiving a doc's updates", ->
|
|
|
|
before (done) ->
|
|
|
|
TrackChangesClient.unarchiveProject @project_id, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should restore doc changes", (done) ->
|
|
|
|
db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
|
|
|
|
throw error if error?
|
|
|
|
count.should.equal 20
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should remove doc marked as inS3", (done) ->
|
2016-01-15 10:49:07 -05:00
|
|
|
db.docHistoryStats.findOne {doc_id: ObjectId(@doc_id)}, (error, doc) ->
|
2015-09-03 07:36:32 -04:00
|
|
|
throw error if error?
|
2016-01-15 10:49:07 -05:00
|
|
|
doc.should.not.contain.key('inS3')
|
|
|
|
doc.should.not.contain.key('lastVersion')
|
2015-09-03 07:36:32 -04:00
|
|
|
done()
|