add unarchive acceptance tests

This commit is contained in:
Henrique Dias 2015-09-03 08:36:32 -03:00
parent da9e7dc7e1
commit c5a8a249c6
3 changed files with 59 additions and 12 deletions

View file

@ -72,10 +72,13 @@ module.exports = MongoAWS =
op.doc_id = ObjectId(op.doc_id)
op.project_id = ObjectId(op.project_id)
bulk.find({_id:op._id}).upsert().updateOne(op)
bulk.execute (err, result) ->
if err?
logger.error err:err, "error bulking ReadlineStream"
else
logger.log count:ops.length, result:result, "bulked ReadlineStream"
cb(err)
if ops.length > 0
bulk.execute (err, result) ->
if err?
logger.error err:err, "error bulking ReadlineStream"
else
logger.log count:ops.length, result:result, "bulked ReadlineStream"
cb(err)
else
cb()

View file

@ -59,17 +59,18 @@ describe "Archiving updates", ->
throw error if error?
done()
after: () ->
after (done) ->
MockWebApi.getUser.restore()
db.docHistory.remove {project_id: ObjectId(@project_id)}
TrackChangesClient.removeS3Doc @project_id, @doc_id, done
describe "archiving a doc's updates", ->
before (done) ->
TrackChangesClient.archiveProject @project_id, (error) ->
throw error if error?
done()
it "should remain one doc", (done) ->
it "should remain one doc change", (done) ->
db.docHistory.count { doc_id: ObjectId(@doc_id) }, (error, count) ->
throw error if error?
count.should.equal 1
@ -85,4 +86,27 @@ describe "Archiving updates", ->
db.docHistory.findOne { doc_id: ObjectId(@doc_id) }, (error, doc) ->
throw error if error?
doc.v.should.equal 20
done()
done()
it "should store twenty doc changes in S3", (done) ->
TrackChangesClient.getS3Doc @project_id, @doc_id, (error, res, doc) =>
doc.length.should.equal 20
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) ->
db.docHistory.count { doc_id: ObjectId(@doc_id), inS3 : true }, (error, count) ->
throw error if error?
count.should.equal 0
done()

View file

@ -1,6 +1,7 @@
request = require "request"
rclient = require("redis").createClient() # Only works locally for now
{db, ObjectId} = require "../../../../app/js/mongojs"
Settings = require "settings-sharelatex"
module.exports = TrackChangesClient =
flushAndGetCompressedUpdates: (project_id, doc_id, callback = (error, updates) ->) ->
@ -85,4 +86,23 @@ module.exports = TrackChangesClient =
url: "http://localhost:3015/project/#{project_id}/unarchive"
}, (error, response, body) =>
response.statusCode.should.equal 204
callback(error)
callback(error)
buildS3Options: (content, key)->
return {
aws:
key: Settings.filestore.s3.key
secret: Settings.filestore.s3.secret
bucket: Settings.filestore.stores.user_files
timeout: 30 * 1000
json: content
uri:"https://#{Settings.filestore.stores.user_files}.s3.amazonaws.com/#{key}"
}
getS3Doc: (project_id, doc_id, callback = (error, res, body) ->) ->
options = TrackChangesClient.buildS3Options(true, project_id+"/changes-"+doc_id)
request.get options, callback
removeS3Doc: (project_id, doc_id, callback = (error, res, body) ->) ->
options = TrackChangesClient.buildS3Options(true, project_id+"/changes-"+doc_id)
request.del options, callback