DocManagerTests.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. no-dupe-keys,
  5. no-return-assign,
  6. no-unused-vars,
  7. */
  8. // TODO: This file was created by bulk-decaffeinate.
  9. // Fix any style issues and re-enable lint.
  10. /*
  11. * decaffeinate suggestions:
  12. * DS102: Remove unnecessary code created because of implicit returns
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. const SandboxedModule = require('sandboxed-module')
  16. const sinon = require('sinon')
  17. const chai = require('chai')
  18. const { assert } = require('chai')
  19. chai.should()
  20. const { expect } = chai
  21. const modulePath = require('path').join(__dirname, '../../../app/js/DocManager')
  22. const { ObjectId } = require('mongojs')
  23. const Errors = require('../../../app/js/Errors')
  24. describe('DocManager', function () {
  25. beforeEach(function () {
  26. this.DocManager = SandboxedModule.require(modulePath, {
  27. requires: {
  28. './MongoManager': (this.MongoManager = {}),
  29. './DocArchiveManager': (this.DocArchiveManager = {}),
  30. './RangeManager': (this.RangeManager = {
  31. jsonRangesToMongo(r) {
  32. return r
  33. },
  34. shouldUpdateRanges: sinon.stub().returns(false)
  35. }),
  36. 'logger-sharelatex': (this.logger = {
  37. log: sinon.stub(),
  38. warn() {},
  39. err() {}
  40. })
  41. }
  42. })
  43. this.doc_id = ObjectId().toString()
  44. this.project_id = ObjectId().toString()
  45. this.another_project_id = ObjectId().toString()
  46. this.callback = sinon.stub()
  47. return (this.stubbedError = new Error('blew up'))
  48. })
  49. describe('checkDocExists', function () {
  50. beforeEach(function () {
  51. return (this.DocManager._getDoc = sinon.stub())
  52. })
  53. it('should call get doc with a quick filter', function (done) {
  54. this.DocManager._getDoc.callsArgWith(3, null, { _id: this.doc_id })
  55. return this.DocManager.checkDocExists(
  56. this.project_id,
  57. this.doc_id,
  58. (err, exist) => {
  59. exist.should.equal(true)
  60. this.DocManager._getDoc
  61. .calledWith(this.project_id, this.doc_id, { _id: 1, inS3: true })
  62. .should.equal(true)
  63. return done()
  64. }
  65. )
  66. })
  67. it('should return false when doc is not there', function (done) {
  68. this.DocManager._getDoc.callsArgWith(3, null)
  69. return this.DocManager.checkDocExists(
  70. this.project_id,
  71. this.doc_id,
  72. (err, exist) => {
  73. exist.should.equal(false)
  74. return done()
  75. }
  76. )
  77. })
  78. return it('should return error when get doc errors', function (done) {
  79. this.DocManager._getDoc.callsArgWith(3, 'error')
  80. return this.DocManager.checkDocExists(
  81. this.project_id,
  82. this.doc_id,
  83. (err, exist) => {
  84. err.should.equal('error')
  85. return done()
  86. }
  87. )
  88. })
  89. })
  90. describe('getFullDoc', function () {
  91. beforeEach(function () {
  92. this.DocManager._getDoc = sinon.stub()
  93. return (this.doc = {
  94. _id: this.doc_id,
  95. lines: ['2134']
  96. })
  97. })
  98. it('should call get doc with a quick filter', function (done) {
  99. this.DocManager._getDoc.callsArgWith(3, null, this.doc)
  100. return this.DocManager.getFullDoc(
  101. this.project_id,
  102. this.doc_id,
  103. (err, doc) => {
  104. doc.should.equal(this.doc)
  105. this.DocManager._getDoc
  106. .calledWith(this.project_id, this.doc_id, {
  107. lines: true,
  108. rev: true,
  109. deleted: true,
  110. version: true,
  111. ranges: true,
  112. inS3: true
  113. })
  114. .should.equal(true)
  115. return done()
  116. }
  117. )
  118. })
  119. return it('should return error when get doc errors', function (done) {
  120. this.DocManager._getDoc.callsArgWith(3, 'error')
  121. return this.DocManager.getFullDoc(
  122. this.project_id,
  123. this.doc_id,
  124. (err, exist) => {
  125. err.should.equal('error')
  126. return done()
  127. }
  128. )
  129. })
  130. })
  131. describe('getRawDoc', function () {
  132. beforeEach(function () {
  133. this.DocManager._getDoc = sinon.stub()
  134. return (this.doc = { lines: ['2134'] })
  135. })
  136. it('should call get doc with a quick filter', function (done) {
  137. this.DocManager._getDoc.callsArgWith(3, null, this.doc)
  138. return this.DocManager.getDocLines(
  139. this.project_id,
  140. this.doc_id,
  141. (err, doc) => {
  142. doc.should.equal(this.doc)
  143. this.DocManager._getDoc
  144. .calledWith(this.project_id, this.doc_id, {
  145. lines: true,
  146. inS3: true
  147. })
  148. .should.equal(true)
  149. return done()
  150. }
  151. )
  152. })
  153. return it('should return error when get doc errors', function (done) {
  154. this.DocManager._getDoc.callsArgWith(3, 'error')
  155. return this.DocManager.getDocLines(
  156. this.project_id,
  157. this.doc_id,
  158. (err, exist) => {
  159. err.should.equal('error')
  160. return done()
  161. }
  162. )
  163. })
  164. })
  165. describe('getDoc', function () {
  166. beforeEach(function () {
  167. this.project = { name: 'mock-project' }
  168. this.doc = {
  169. _id: this.doc_id,
  170. project_id: this.project_id,
  171. lines: ['mock-lines']
  172. }
  173. this.version = 42
  174. this.MongoManager.findDoc = sinon.stub()
  175. return (this.MongoManager.getDocVersion = sinon
  176. .stub()
  177. .yields(null, this.version))
  178. })
  179. describe('when using a filter', function () {
  180. beforeEach(function () {
  181. return this.MongoManager.findDoc.yields(null, this.doc)
  182. })
  183. it('should error if inS3 is not set to true', function (done) {
  184. return this.DocManager._getDoc(
  185. this.project_id,
  186. this.doc_id,
  187. { inS3: false },
  188. (err) => {
  189. expect(err).to.exist
  190. return done()
  191. }
  192. )
  193. })
  194. it('should always get inS3 even when no filter is passed', function (done) {
  195. return this.DocManager._getDoc(
  196. this.project_id,
  197. this.doc_id,
  198. undefined,
  199. (err) => {
  200. this.MongoManager.findDoc.called.should.equal(false)
  201. expect(err).to.exist
  202. return done()
  203. }
  204. )
  205. })
  206. return it('should not error if inS3 is set to true', function (done) {
  207. return this.DocManager._getDoc(
  208. this.project_id,
  209. this.doc_id,
  210. { inS3: true },
  211. (err) => {
  212. expect(err).to.not.exist
  213. return done()
  214. }
  215. )
  216. })
  217. })
  218. describe('when the doc is in the doc collection', function () {
  219. beforeEach(function () {
  220. this.MongoManager.findDoc.yields(null, this.doc)
  221. return this.DocManager._getDoc(
  222. this.project_id,
  223. this.doc_id,
  224. { version: true, inS3: true },
  225. this.callback
  226. )
  227. })
  228. it('should get the doc from the doc collection', function () {
  229. return this.MongoManager.findDoc
  230. .calledWith(this.project_id, this.doc_id)
  231. .should.equal(true)
  232. })
  233. it('should get the doc version from the docOps collection', function () {
  234. return this.MongoManager.getDocVersion
  235. .calledWith(this.doc_id)
  236. .should.equal(true)
  237. })
  238. return it('should return the callback with the doc with the version', function () {
  239. this.callback.called.should.equal(true)
  240. const doc = this.callback.args[0][1]
  241. doc.lines.should.equal(this.doc.lines)
  242. return doc.version.should.equal(this.version)
  243. })
  244. })
  245. describe('without the version filter', function () {
  246. beforeEach(function () {
  247. this.MongoManager.findDoc.yields(null, this.doc)
  248. return this.DocManager._getDoc(
  249. this.project_id,
  250. this.doc_id,
  251. { version: false, inS3: true },
  252. this.callback
  253. )
  254. })
  255. return it('should not get the doc version from the docOps collection', function () {
  256. return this.MongoManager.getDocVersion.called.should.equal(false)
  257. })
  258. })
  259. describe('when MongoManager.findDoc errors', function () {
  260. beforeEach(function () {
  261. this.MongoManager.findDoc.yields(this.stubbedError)
  262. return this.DocManager._getDoc(
  263. this.project_id,
  264. this.doc_id,
  265. { version: true, inS3: true },
  266. this.callback
  267. )
  268. })
  269. return it('should return the error', function () {
  270. return this.callback.calledWith(this.stubbedError).should.equal(true)
  271. })
  272. })
  273. describe('when the doc is archived', function () {
  274. beforeEach(function () {
  275. this.doc = {
  276. _id: this.doc_id,
  277. project_id: this.project_id,
  278. lines: ['mock-lines'],
  279. inS3: true
  280. }
  281. this.MongoManager.findDoc.yields(null, this.doc)
  282. this.DocArchiveManager.unarchiveDoc = (
  283. project_id,
  284. doc_id,
  285. callback
  286. ) => {
  287. this.doc.inS3 = false
  288. return callback()
  289. }
  290. sinon.spy(this.DocArchiveManager, 'unarchiveDoc')
  291. return this.DocManager._getDoc(
  292. this.project_id,
  293. this.doc_id,
  294. { version: true, inS3: true },
  295. this.callback
  296. )
  297. })
  298. it('should call the DocArchive to unarchive the doc', function () {
  299. return this.DocArchiveManager.unarchiveDoc
  300. .calledWith(this.project_id, this.doc_id)
  301. .should.equal(true)
  302. })
  303. it('should look up the doc twice', function () {
  304. return this.MongoManager.findDoc.calledTwice.should.equal(true)
  305. })
  306. return it('should return the doc', function () {
  307. return this.callback.calledWith(null, this.doc).should.equal(true)
  308. })
  309. })
  310. return describe('when the doc does not exist in the docs collection', function () {
  311. beforeEach(function () {
  312. this.MongoManager.findDoc = sinon.stub().yields(null, null)
  313. return this.DocManager._getDoc(
  314. this.project_id,
  315. this.doc_id,
  316. { version: true, inS3: true },
  317. this.callback
  318. )
  319. })
  320. return it('should return a NotFoundError', function () {
  321. return this.callback
  322. .calledWith(
  323. sinon.match.has(
  324. 'message',
  325. `No such doc: ${this.doc_id} in project ${this.project_id}`
  326. )
  327. )
  328. .should.equal(true)
  329. })
  330. })
  331. })
  332. describe('getAllNonDeletedDocs', function () {
  333. describe('when the project exists', function () {
  334. beforeEach(function () {
  335. this.docs = [
  336. {
  337. _id: this.doc_id,
  338. project_id: this.project_id,
  339. lines: ['mock-lines']
  340. }
  341. ]
  342. this.MongoManager.getProjectsDocs = sinon
  343. .stub()
  344. .callsArgWith(3, null, this.docs)
  345. this.DocArchiveManager.unArchiveAllDocs = sinon
  346. .stub()
  347. .callsArgWith(1, null, this.docs)
  348. this.filter = { lines: true }
  349. return this.DocManager.getAllNonDeletedDocs(
  350. this.project_id,
  351. this.filter,
  352. this.callback
  353. )
  354. })
  355. it('should get the project from the database', function () {
  356. return this.MongoManager.getProjectsDocs
  357. .calledWith(this.project_id, { include_deleted: false }, this.filter)
  358. .should.equal(true)
  359. })
  360. return it('should return the docs', function () {
  361. return this.callback.calledWith(null, this.docs).should.equal(true)
  362. })
  363. })
  364. return describe('when there are no docs for the project', function () {
  365. beforeEach(function () {
  366. this.MongoManager.getProjectsDocs = sinon
  367. .stub()
  368. .callsArgWith(3, null, null)
  369. this.DocArchiveManager.unArchiveAllDocs = sinon
  370. .stub()
  371. .callsArgWith(1, null)
  372. return this.DocManager.getAllNonDeletedDocs(
  373. this.project_id,
  374. this.filter,
  375. this.callback
  376. )
  377. })
  378. return it('should return a NotFoundError', function () {
  379. return this.callback
  380. .calledWith(
  381. sinon.match.has('message', `No docs for project ${this.project_id}`)
  382. )
  383. .should.equal(true)
  384. })
  385. })
  386. })
  387. describe('deleteDoc', function () {
  388. describe('when the doc exists', function () {
  389. beforeEach(function () {
  390. this.lines = ['mock', 'doc', 'lines']
  391. this.rev = 77
  392. this.DocManager.checkDocExists = sinon
  393. .stub()
  394. .callsArgWith(2, null, true)
  395. this.MongoManager.markDocAsDeleted = sinon.stub().callsArg(2)
  396. return this.DocManager.deleteDoc(
  397. this.project_id,
  398. this.doc_id,
  399. this.callback
  400. )
  401. })
  402. it('should get the doc', function () {
  403. return this.DocManager.checkDocExists
  404. .calledWith(this.project_id, this.doc_id)
  405. .should.equal(true)
  406. })
  407. it('should mark doc as deleted', function () {
  408. return this.MongoManager.markDocAsDeleted
  409. .calledWith(this.project_id, this.doc_id)
  410. .should.equal(true)
  411. })
  412. return it('should return the callback', function () {
  413. return this.callback.called.should.equal(true)
  414. })
  415. })
  416. return describe('when the doc does not exist', function () {
  417. beforeEach(function () {
  418. this.DocManager.checkDocExists = sinon
  419. .stub()
  420. .callsArgWith(2, null, false)
  421. return this.DocManager.deleteDoc(
  422. this.project_id,
  423. this.doc_id,
  424. this.callback
  425. )
  426. })
  427. return it('should return a NotFoundError', function () {
  428. return this.callback
  429. .calledWith(
  430. sinon.match.has(
  431. 'message',
  432. `No such project/doc to delete: ${this.project_id}/${this.doc_id}`
  433. )
  434. )
  435. .should.equal(true)
  436. })
  437. })
  438. })
  439. return describe('updateDoc', function () {
  440. beforeEach(function () {
  441. this.oldDocLines = ['old', 'doc', 'lines']
  442. this.newDocLines = ['new', 'doc', 'lines']
  443. this.originalRanges = {
  444. changes: [
  445. {
  446. id: ObjectId().toString(),
  447. op: { i: 'foo', p: 3 },
  448. meta: {
  449. user_id: ObjectId().toString(),
  450. ts: new Date().toString()
  451. }
  452. }
  453. ]
  454. }
  455. this.newRanges = {
  456. changes: [
  457. {
  458. id: ObjectId().toString(),
  459. op: { i: 'bar', p: 6 },
  460. meta: {
  461. user_id: ObjectId().toString(),
  462. ts: new Date().toString()
  463. }
  464. }
  465. ]
  466. }
  467. this.version = 42
  468. this.doc = {
  469. _id: this.doc_id,
  470. project_id: this.project_id,
  471. lines: this.oldDocLines,
  472. rev: (this.rev = 5),
  473. version: this.version,
  474. ranges: this.originalRanges
  475. }
  476. this.MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3)
  477. this.MongoManager.setDocVersion = sinon.stub().yields()
  478. return (this.DocManager._getDoc = sinon.stub())
  479. })
  480. describe('when only the doc lines have changed', function () {
  481. beforeEach(function () {
  482. this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
  483. return this.DocManager.updateDoc(
  484. this.project_id,
  485. this.doc_id,
  486. this.newDocLines,
  487. this.version,
  488. this.originalRanges,
  489. this.callback
  490. )
  491. })
  492. it('should get the existing doc', function () {
  493. return this.DocManager._getDoc
  494. .calledWith(this.project_id, this.doc_id, {
  495. version: true,
  496. rev: true,
  497. lines: true,
  498. version: true,
  499. ranges: true,
  500. inS3: true
  501. })
  502. .should.equal(true)
  503. })
  504. it('should upsert the document to the doc collection', function () {
  505. return this.MongoManager.upsertIntoDocCollection
  506. .calledWith(this.project_id, this.doc_id, { lines: this.newDocLines })
  507. .should.equal(true)
  508. })
  509. it('should not update the version', function () {
  510. return this.MongoManager.setDocVersion.called.should.equal(false)
  511. })
  512. return it('should return the callback with the new rev', function () {
  513. return this.callback
  514. .calledWith(null, true, this.rev + 1)
  515. .should.equal(true)
  516. })
  517. })
  518. describe('when the doc ranges have changed', function () {
  519. beforeEach(function () {
  520. this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
  521. this.RangeManager.shouldUpdateRanges.returns(true)
  522. return this.DocManager.updateDoc(
  523. this.project_id,
  524. this.doc_id,
  525. this.oldDocLines,
  526. this.version,
  527. this.newRanges,
  528. this.callback
  529. )
  530. })
  531. it('should upsert the ranges', function () {
  532. return this.MongoManager.upsertIntoDocCollection
  533. .calledWith(this.project_id, this.doc_id, { ranges: this.newRanges })
  534. .should.equal(true)
  535. })
  536. it('should not update the version', function () {
  537. return this.MongoManager.setDocVersion.called.should.equal(false)
  538. })
  539. return it('should return the callback with the new rev', function () {
  540. return this.callback
  541. .calledWith(null, true, this.rev + 1)
  542. .should.equal(true)
  543. })
  544. })
  545. describe('when only the version has changed', function () {
  546. beforeEach(function () {
  547. this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
  548. return this.DocManager.updateDoc(
  549. this.project_id,
  550. this.doc_id,
  551. this.oldDocLines,
  552. this.version + 1,
  553. this.originalRanges,
  554. this.callback
  555. )
  556. })
  557. it('should not change the lines or ranges', function () {
  558. return this.MongoManager.upsertIntoDocCollection.called.should.equal(
  559. false
  560. )
  561. })
  562. it('should update the version', function () {
  563. return this.MongoManager.setDocVersion
  564. .calledWith(this.doc_id, this.version + 1)
  565. .should.equal(true)
  566. })
  567. return it('should return the callback with the old rev', function () {
  568. return this.callback.calledWith(null, true, this.rev).should.equal(true)
  569. })
  570. })
  571. describe('when the doc has not changed at all', function () {
  572. beforeEach(function () {
  573. this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
  574. return this.DocManager.updateDoc(
  575. this.project_id,
  576. this.doc_id,
  577. this.oldDocLines,
  578. this.version,
  579. this.originalRanges,
  580. this.callback
  581. )
  582. })
  583. it('should not update the ranges or lines', function () {
  584. return this.MongoManager.upsertIntoDocCollection.called.should.equal(
  585. false
  586. )
  587. })
  588. it('should not update the version', function () {
  589. return this.MongoManager.setDocVersion.called.should.equal(false)
  590. })
  591. return it('should return the callback with the old rev and modified == false', function () {
  592. return this.callback
  593. .calledWith(null, false, this.rev)
  594. .should.equal(true)
  595. })
  596. })
  597. describe('when the version is null', function () {
  598. beforeEach(function () {
  599. return this.DocManager.updateDoc(
  600. this.project_id,
  601. this.doc_id,
  602. this.newDocLines,
  603. null,
  604. this.originalRanges,
  605. this.callback
  606. )
  607. })
  608. return it('should return an error', function () {
  609. return this.callback
  610. .calledWith(
  611. sinon.match.has('message', 'no lines, version or ranges provided')
  612. )
  613. .should.equal(true)
  614. })
  615. })
  616. describe('when the lines are null', function () {
  617. beforeEach(function () {
  618. return this.DocManager.updateDoc(
  619. this.project_id,
  620. this.doc_id,
  621. null,
  622. this.version,
  623. this.originalRanges,
  624. this.callback
  625. )
  626. })
  627. return it('should return an error', function () {
  628. return this.callback
  629. .calledWith(
  630. sinon.match.has('message', 'no lines, version or ranges provided')
  631. )
  632. .should.equal(true)
  633. })
  634. })
  635. describe('when the ranges are null', function () {
  636. beforeEach(function () {
  637. return this.DocManager.updateDoc(
  638. this.project_id,
  639. this.doc_id,
  640. this.newDocLines,
  641. this.version,
  642. null,
  643. this.callback
  644. )
  645. })
  646. return it('should return an error', function () {
  647. return this.callback
  648. .calledWith(
  649. sinon.match.has('message', 'no lines, version or ranges provided')
  650. )
  651. .should.equal(true)
  652. })
  653. })
  654. describe('when there is a generic error getting the doc', function () {
  655. beforeEach(function () {
  656. this.error = new Error('doc could not be found')
  657. this.DocManager._getDoc = sinon
  658. .stub()
  659. .callsArgWith(3, this.error, null, null)
  660. return this.DocManager.updateDoc(
  661. this.project_id,
  662. this.doc_id,
  663. this.newDocLines,
  664. this.version,
  665. this.originalRanges,
  666. this.callback
  667. )
  668. })
  669. it('should not upsert the document to the doc collection', function () {
  670. return this.MongoManager.upsertIntoDocCollection.called.should.equal(
  671. false
  672. )
  673. })
  674. return it('should return the callback with the error', function () {
  675. return this.callback.calledWith(this.error).should.equal(true)
  676. })
  677. })
  678. describe('when the doc lines have not changed', function () {
  679. beforeEach(function () {
  680. this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, this.doc)
  681. return this.DocManager.updateDoc(
  682. this.project_id,
  683. this.doc_id,
  684. this.oldDocLines.slice(),
  685. this.version,
  686. this.originalRanges,
  687. this.callback
  688. )
  689. })
  690. it('should not update the doc', function () {
  691. return this.MongoManager.upsertIntoDocCollection.called.should.equal(
  692. false
  693. )
  694. })
  695. return it('should return the callback with the existing rev', function () {
  696. return this.callback
  697. .calledWith(null, false, this.rev)
  698. .should.equal(true)
  699. })
  700. })
  701. return describe('when the doc does not exist', function () {
  702. beforeEach(function () {
  703. this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, null, null)
  704. return this.DocManager.updateDoc(
  705. this.project_id,
  706. this.doc_id,
  707. this.newDocLines,
  708. this.version,
  709. this.originalRanges,
  710. this.callback
  711. )
  712. })
  713. it('should upsert the document to the doc collection', function () {
  714. return this.MongoManager.upsertIntoDocCollection
  715. .calledWith(this.project_id, this.doc_id, {
  716. lines: this.newDocLines,
  717. ranges: this.originalRanges
  718. })
  719. .should.equal(true)
  720. })
  721. it('should set the version', function () {
  722. return this.MongoManager.setDocVersion
  723. .calledWith(this.doc_id, this.version)
  724. .should.equal(true)
  725. })
  726. return it('should return the callback with the new rev', function () {
  727. return this.callback.calledWith(null, true, 1).should.equal(true)
  728. })
  729. })
  730. })
  731. })