mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
init archive acceptance tests
This commit is contained in:
parent
7de103af68
commit
da9e7dc7e1
4 changed files with 129 additions and 3 deletions
|
@ -36,7 +36,7 @@ module.exports = DocArchiveManager =
|
|||
else
|
||||
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
|
||||
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
|
||||
logger.log doc_id:doc_id, error: error, "mongoexport"
|
||||
logger.log doc_id:doc_id, error: error, "export to S3"
|
||||
MongoManager.markDocHistoryAsArchived doc_id, update, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
|
@ -59,7 +59,7 @@ module.exports = DocArchiveManager =
|
|||
return callback()
|
||||
else
|
||||
MongoAWS.unArchiveDocHistory project_id, doc_id, (error) ->
|
||||
logger.log doc_id:doc_id, error: error, "mongoimport"
|
||||
logger.log doc_id:doc_id, error: error, "import from S3"
|
||||
MongoManager.markDocHistoryAsUnarchived doc_id, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
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
|
||||
|
||||
MockWebApi.users[@user_id] = @user =
|
||||
email: "user@sharelatex.com"
|
||||
first_name: "Leo"
|
||||
last_name: "Lion"
|
||||
id: @user_id
|
||||
sinon.spy MockWebApi, "getUser"
|
||||
|
||||
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()
|
||||
|
||||
after: () ->
|
||||
MockWebApi.getUser.restore()
|
||||
|
||||
describe "archiving a doc's updates", ->
|
||||
before (done) ->
|
||||
|
||||
TrackChangesClient.archiveProject @project_id, (error) ->
|
||||
throw error if error?
|
||||
done()
|
||||
|
||||
it "should remain one doc", (done) ->
|
||||
db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
|
||||
throw error if error?
|
||||
count.should.equal 1
|
||||
done()
|
||||
|
||||
it "should remained doc marked as inS3", (done) ->
|
||||
db.docHistory.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
|
||||
throw error if error?
|
||||
doc.inS3.should.equal true
|
||||
done()
|
||||
|
||||
it "should remained doc have last version", (done) ->
|
||||
db.docHistory.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
|
||||
throw error if error?
|
||||
doc.v.should.equal 20
|
||||
done()
|
|
@ -0,0 +1,24 @@
|
|||
express = require("express")
|
||||
app = express()
|
||||
|
||||
module.exports = MockDocUpdaterApi =
|
||||
docs: {}
|
||||
|
||||
getAllDoc: (project_id, callback = (error) ->) ->
|
||||
callback null, @docs
|
||||
|
||||
run: () ->
|
||||
app.get "/project/:project_id/doc", (req, res, next) =>
|
||||
@getAllDoc req.params.project_id, (error, docs) ->
|
||||
if error?
|
||||
res.send 500
|
||||
if !docs?
|
||||
res.send 404
|
||||
else
|
||||
res.send JSON.stringify docs
|
||||
|
||||
app.listen 3016, (error) ->
|
||||
throw error if error?
|
||||
|
||||
MockDocUpdaterApi.run()
|
||||
|
|
@ -71,4 +71,18 @@ module.exports = TrackChangesClient =
|
|||
"X-User-Id": user_id
|
||||
}, (error, response, body) =>
|
||||
response.statusCode.should.equal 204
|
||||
callback null
|
||||
callback null
|
||||
|
||||
archiveProject: (project_id, callback = (error) ->) ->
|
||||
request.get {
|
||||
url: "http://localhost:3015/project/#{project_id}/archive"
|
||||
}, (error, response, body) =>
|
||||
response.statusCode.should.equal 204
|
||||
callback(error)
|
||||
|
||||
unarchiveProject: (project_id, callback = (error) ->) ->
|
||||
request.get {
|
||||
url: "http://localhost:3015/project/#{project_id}/unarchive"
|
||||
}, (error, response, body) =>
|
||||
response.statusCode.should.equal 204
|
||||
callback(error)
|
Loading…
Reference in a new issue