DocManagerTests.js 23 KB

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