2014-04-30 08:06:12 -04:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
{ObjectId} = require "mongojs"
|
|
|
|
async = require "async"
|
2018-05-23 06:27:31 -04:00
|
|
|
DocstoreApp = require "./helpers/DocstoreApp"
|
2014-04-30 08:06:12 -04:00
|
|
|
|
|
|
|
DocstoreClient = require "./helpers/DocstoreClient"
|
|
|
|
|
|
|
|
describe "Getting all docs", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@project_id = ObjectId()
|
|
|
|
@docs = [{
|
|
|
|
_id: ObjectId()
|
2015-01-27 12:05:07 -05:00
|
|
|
lines: ["one", "two", "three"]
|
2016-12-09 09:37:24 -05:00
|
|
|
ranges: {"mock": "one"}
|
2014-04-30 08:06:12 -04:00
|
|
|
rev: 2
|
|
|
|
}, {
|
|
|
|
_id: ObjectId()
|
2015-01-27 12:05:07 -05:00
|
|
|
lines: ["aaa", "bbb", "ccc"]
|
2016-12-09 09:37:24 -05:00
|
|
|
ranges: {"mock": "two"}
|
2014-04-30 08:06:12 -04:00
|
|
|
rev: 4
|
|
|
|
}, {
|
|
|
|
_id: ObjectId()
|
2015-01-27 12:05:07 -05:00
|
|
|
lines: ["111", "222", "333"]
|
2016-12-09 09:37:24 -05:00
|
|
|
ranges: {"mock": "three"}
|
2014-04-30 08:06:12 -04:00
|
|
|
rev: 6
|
|
|
|
}]
|
2016-12-05 09:37:44 -05:00
|
|
|
@deleted_doc = {
|
|
|
|
_id: ObjectId()
|
|
|
|
lines: ["deleted"]
|
2016-12-09 09:37:24 -05:00
|
|
|
ranges: {"mock": "four"}
|
2016-12-05 09:37:44 -05:00
|
|
|
rev: 8
|
|
|
|
}
|
2016-12-05 09:21:49 -05:00
|
|
|
version = 42
|
2015-02-20 09:28:16 -05:00
|
|
|
jobs = for doc in @docs
|
|
|
|
do (doc) =>
|
|
|
|
(callback) =>
|
2016-12-09 09:37:24 -05:00
|
|
|
DocstoreClient.createDoc @project_id, doc._id, doc.lines, version, doc.ranges, callback
|
2016-12-05 09:37:44 -05:00
|
|
|
jobs.push (cb) =>
|
2016-12-09 09:37:24 -05:00
|
|
|
DocstoreClient.createDoc @project_id, @deleted_doc._id, @deleted_doc.lines, version, @deleted_doc.ranges, (err)=>
|
2016-12-05 09:58:57 -05:00
|
|
|
DocstoreClient.deleteDoc @project_id, @deleted_doc._id, cb
|
2018-05-23 06:27:31 -04:00
|
|
|
jobs.unshift (cb)->
|
|
|
|
DocstoreApp.ensureRunning cb
|
2015-02-20 09:28:16 -05:00
|
|
|
async.series jobs, done
|
2014-04-30 08:06:12 -04:00
|
|
|
|
2016-12-09 09:37:24 -05:00
|
|
|
it "getAllDocs should return all the (non-deleted) docs", (done) ->
|
2014-04-30 08:06:12 -04:00
|
|
|
DocstoreClient.getAllDocs @project_id, (error, res, docs) =>
|
|
|
|
throw error if error?
|
|
|
|
docs.length.should.equal @docs.length
|
|
|
|
for doc, i in docs
|
|
|
|
doc.lines.should.deep.equal @docs[i].lines
|
|
|
|
done()
|
|
|
|
|
2016-12-09 09:37:24 -05:00
|
|
|
it "getAllRanges should return all the (non-deleted) doc ranges", (done) ->
|
|
|
|
DocstoreClient.getAllRanges @project_id, (error, res, docs) =>
|
|
|
|
throw error if error?
|
|
|
|
docs.length.should.equal @docs.length
|
|
|
|
for doc, i in docs
|
|
|
|
doc.ranges.should.deep.equal @docs[i].ranges
|
|
|
|
done()
|
|
|
|
|
2015-01-27 12:05:07 -05:00
|
|
|
|