overleaf/services/docstore/test/acceptance/coffee/GettingAllDocsTests.coffee

50 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2014-04-30 08:06:12 -04:00
sinon = require "sinon"
chai = require("chai")
chai.should()
{ObjectId} = require "mongojs"
async = require "async"
DocstoreClient = require "./helpers/DocstoreClient"
describe "Getting all docs", ->
beforeEach (done) ->
@project_id = ObjectId()
@docs = [{
_id: ObjectId()
lines: ["one", "two", "three"]
2014-04-30 08:06:12 -04:00
rev: 2
}, {
_id: ObjectId()
lines: ["aaa", "bbb", "ccc"]
2014-04-30 08:06:12 -04:00
rev: 4
}, {
_id: ObjectId()
lines: ["111", "222", "333"]
2014-04-30 08:06:12 -04:00
rev: 6
}]
@deleted_doc = {
_id: ObjectId()
lines: ["deleted"]
rev: 8
}
2016-12-05 09:21:49 -05:00
version = 42
ranges = 42
jobs = for doc in @docs
do (doc) =>
(callback) =>
DocstoreClient.createDoc @project_id, doc._id, doc.lines, version, ranges, callback
jobs.push (cb) =>
DocstoreClient.createDoc @project_id, @deleted_doc._id, @deleted_doc.lines, version, {}, (err)=>
DocstoreClient.deleteDoc @project_id, @deleted_doc._id, cb
async.series jobs, done
2014-04-30 08:06:12 -04:00
it "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()