mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Improve testing of archiving and be explicit about include_deleted parameter
This commit is contained in:
parent
7717625534
commit
3d195de3e9
6 changed files with 13 additions and 9 deletions
|
@ -11,7 +11,7 @@ thirtySeconds = 30 * 1000
|
||||||
module.exports = DocArchive =
|
module.exports = DocArchive =
|
||||||
|
|
||||||
archiveAllDocs: (project_id, callback = (err, docs) ->) ->
|
archiveAllDocs: (project_id, callback = (err, docs) ->) ->
|
||||||
MongoManager.getProjectsDocs project_id, true, (err, docs) ->
|
MongoManager.getProjectsDocs project_id, {include_deleted: true}, (err, docs) ->
|
||||||
if err?
|
if err?
|
||||||
return callback(err)
|
return callback(err)
|
||||||
else if !docs?
|
else if !docs?
|
||||||
|
|
|
@ -32,7 +32,7 @@ module.exports = DocManager =
|
||||||
|
|
||||||
getAllNonDeletedDocs: (project_id, callback = (error, docs) ->) ->
|
getAllNonDeletedDocs: (project_id, callback = (error, docs) ->) ->
|
||||||
DocArchive.unArchiveAllDocs project_id, (error) ->
|
DocArchive.unArchiveAllDocs project_id, (error) ->
|
||||||
MongoManager.getProjectsDocs project_id, false, (error, docs) ->
|
MongoManager.getProjectsDocs project_id, {include_deleted: false}, (error, docs) ->
|
||||||
if err?
|
if err?
|
||||||
return callback(error)
|
return callback(error)
|
||||||
else if !docs?
|
else if !docs?
|
||||||
|
|
|
@ -6,9 +6,9 @@ module.exports = MongoManager =
|
||||||
db.docs.find {_id: ObjectId(doc_id.toString()), project_id: ObjectId(project_id.toString())}, {}, (error, docs = []) ->
|
db.docs.find {_id: ObjectId(doc_id.toString()), project_id: ObjectId(project_id.toString())}, {}, (error, docs = []) ->
|
||||||
callback error, docs[0]
|
callback error, docs[0]
|
||||||
|
|
||||||
getProjectsDocs: (project_id, include_deleted, callback)->
|
getProjectsDocs: (project_id, options = {include_deleted: true}, callback)->
|
||||||
query = {project_id: ObjectId(project_id.toString())}
|
query = {project_id: ObjectId(project_id.toString())}
|
||||||
if !include_deleted
|
if !options.include_deleted
|
||||||
query.deleted = { $ne: true }
|
query.deleted = { $ne: true }
|
||||||
db.docs.find query, {}, callback
|
db.docs.find query, {}, callback
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ describe "Archiving all docs", ->
|
||||||
DocstoreClient.createDoc @project_id, doc._id, doc.lines, (err)=>
|
DocstoreClient.createDoc @project_id, doc._id, doc.lines, (err)=>
|
||||||
doc.lines[0] = doc.lines[0]+" added"
|
doc.lines[0] = doc.lines[0]+" added"
|
||||||
DocstoreClient.updateDoc @project_id, doc._id, doc.lines, null, callback
|
DocstoreClient.updateDoc @project_id, doc._id, doc.lines, null, callback
|
||||||
|
# Make sure archiving works on deleted docs too
|
||||||
|
jobs.push (cb) =>
|
||||||
|
DocstoreClient.deleteDoc @project_id, @docs[2]._id, cb
|
||||||
async.series jobs, done
|
async.series jobs, done
|
||||||
|
|
||||||
afterEach (done) ->
|
afterEach (done) ->
|
||||||
|
@ -141,10 +144,11 @@ describe "Archiving all docs", ->
|
||||||
describe "Unarchiving all docs", ->
|
describe "Unarchiving all docs", ->
|
||||||
|
|
||||||
it "should unarchive all the docs", (done) ->
|
it "should unarchive all the docs", (done) ->
|
||||||
|
non_deleted_docs = @docs.slice(0,2)
|
||||||
DocstoreClient.archiveAllDoc @project_id, (error, res) =>
|
DocstoreClient.archiveAllDoc @project_id, (error, res) =>
|
||||||
DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
|
DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
|
||||||
throw error if error?
|
throw error if error?
|
||||||
docs.length.should.equal @docs.length
|
docs.length.should.equal non_deleted_docs.length
|
||||||
for doc, i in docs
|
for doc, i in non_deleted_docs
|
||||||
doc.lines.should.deep.equal @docs[i].lines
|
doc.lines.should.deep.equal @docs[i].lines
|
||||||
done()
|
done()
|
||||||
|
|
|
@ -106,7 +106,7 @@ describe "DocManager", ->
|
||||||
|
|
||||||
it "should get the project from the database", ->
|
it "should get the project from the database", ->
|
||||||
@MongoManager.getProjectsDocs
|
@MongoManager.getProjectsDocs
|
||||||
.calledWith(@project_id, false)
|
.calledWith(@project_id, {include_deleted: false})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return the docs", ->
|
it "should return the docs", ->
|
||||||
|
|
|
@ -43,7 +43,7 @@ describe "MongoManager", ->
|
||||||
|
|
||||||
describe "with included_deleted = false", ->
|
describe "with included_deleted = false", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@MongoManager.getProjectsDocs @project_id, false, @callback
|
@MongoManager.getProjectsDocs @project_id, include_deleted: false, @callback
|
||||||
|
|
||||||
it "should find the non-deleted docs via the project_id", ->
|
it "should find the non-deleted docs via the project_id", ->
|
||||||
@db.docs.find
|
@db.docs.find
|
||||||
|
@ -58,7 +58,7 @@ describe "MongoManager", ->
|
||||||
|
|
||||||
describe "with included_deleted = true", ->
|
describe "with included_deleted = true", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@MongoManager.getProjectsDocs @project_id, true, @callback
|
@MongoManager.getProjectsDocs @project_id, include_deleted: true, @callback
|
||||||
|
|
||||||
it "should find all via the project_id", ->
|
it "should find all via the project_id", ->
|
||||||
@db.docs.find
|
@db.docs.find
|
||||||
|
|
Loading…
Reference in a new issue