Improve testing of archiving and be explicit about include_deleted parameter

This commit is contained in:
James Allen 2016-12-05 16:48:01 +00:00
parent 7717625534
commit 3d195de3e9
6 changed files with 13 additions and 9 deletions

View file

@ -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?

View file

@ -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?

View file

@ -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

View file

@ -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()

View file

@ -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", ->

View file

@ -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