ProjectRootDocManagerTests.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. no-useless-escape,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const { expect } = require('chai')
  15. const { ObjectId } = require('mongodb-legacy')
  16. const sinon = require('sinon')
  17. const modulePath =
  18. '../../../../app/src/Features/Project/ProjectRootDocManager.js'
  19. const SandboxedModule = require('sandboxed-module')
  20. describe('ProjectRootDocManager', function () {
  21. beforeEach(function () {
  22. this.project_id = 'project-123'
  23. this.docPaths = {}
  24. this.docId1 = new ObjectId()
  25. this.docId2 = new ObjectId()
  26. this.docId3 = new ObjectId()
  27. this.docId4 = new ObjectId()
  28. this.docPaths[this.docId1] = '/chapter1.tex'
  29. this.docPaths[this.docId2] = '/main.tex'
  30. this.docPaths[this.docId3] = '/nested/chapter1a.tex'
  31. this.docPaths[this.docId4] = '/nested/chapter1b.tex'
  32. this.sl_req_id = 'sl-req-id-123'
  33. this.callback = sinon.stub()
  34. this.globbyFiles = ['a.tex', 'b.tex', 'main.tex']
  35. this.globby = sinon.stub().returns(
  36. new Promise(resolve => {
  37. return resolve(this.globbyFiles)
  38. })
  39. )
  40. this.fs = {
  41. readFile: sinon.stub().callsArgWith(2, new Error('file not found')),
  42. stat: sinon.stub().callsArgWith(1, null, { size: 100 }),
  43. }
  44. return (this.ProjectRootDocManager = SandboxedModule.require(modulePath, {
  45. requires: {
  46. './ProjectEntityHandler': (this.ProjectEntityHandler = {}),
  47. './ProjectEntityUpdateHandler': (this.ProjectEntityUpdateHandler = {}),
  48. './ProjectGetter': (this.ProjectGetter = {}),
  49. '../../infrastructure/GracefulShutdown': {
  50. BackgroundTaskTracker: class {
  51. add() {}
  52. done() {}
  53. },
  54. },
  55. globby: this.globby,
  56. fs: this.fs,
  57. },
  58. }))
  59. })
  60. describe('setRootDocAutomatically', function () {
  61. beforeEach(function () {
  62. this.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().callsArgWith(2)
  63. this.ProjectEntityUpdateHandler.isPathValidForRootDoc = sinon
  64. .stub()
  65. .returns(true)
  66. })
  67. describe('when there is a suitable root doc', function () {
  68. beforeEach(function (done) {
  69. this.docs = {
  70. '/chapter1.tex': {
  71. _id: this.docId1,
  72. lines: [
  73. 'something else',
  74. '\\begin{document}',
  75. 'Hello world',
  76. '\\end{document}',
  77. ],
  78. },
  79. '/main.tex': {
  80. _id: this.docId2,
  81. lines: [
  82. 'different line',
  83. '\\documentclass{article}',
  84. '\\input{chapter1}',
  85. ],
  86. },
  87. '/nested/chapter1a.tex': {
  88. _id: this.docId3,
  89. lines: ['Hello world'],
  90. },
  91. '/nested/chapter1b.tex': {
  92. _id: this.docId4,
  93. lines: ['Hello world'],
  94. },
  95. }
  96. this.ProjectEntityHandler.getAllDocs = sinon
  97. .stub()
  98. .callsArgWith(1, null, this.docs)
  99. this.ProjectRootDocManager.setRootDocAutomatically(
  100. this.project_id,
  101. done
  102. )
  103. })
  104. it('should check the docs of the project', function () {
  105. return this.ProjectEntityHandler.getAllDocs
  106. .calledWith(this.project_id)
  107. .should.equal(true)
  108. })
  109. it('should set the root doc to the doc containing a documentclass', function () {
  110. return this.ProjectEntityUpdateHandler.setRootDoc
  111. .calledWith(this.project_id, this.docId2)
  112. .should.equal(true)
  113. })
  114. })
  115. describe('when the root doc is an Rtex file', function () {
  116. beforeEach(function (done) {
  117. this.docs = {
  118. '/chapter1.tex': {
  119. _id: this.docId1,
  120. lines: ['\\begin{document}', 'Hello world', '\\end{document}'],
  121. },
  122. '/main.Rtex': {
  123. _id: this.docId2,
  124. lines: ['\\documentclass{article}', '\\input{chapter1}'],
  125. },
  126. }
  127. this.ProjectEntityHandler.getAllDocs = sinon
  128. .stub()
  129. .callsArgWith(1, null, this.docs)
  130. return this.ProjectRootDocManager.setRootDocAutomatically(
  131. this.project_id,
  132. done
  133. )
  134. })
  135. it('should set the root doc to the doc containing a documentclass', function () {
  136. return this.ProjectEntityUpdateHandler.setRootDoc
  137. .calledWith(this.project_id, this.docId2)
  138. .should.equal(true)
  139. })
  140. })
  141. describe('when there is no suitable root doc', function () {
  142. beforeEach(function (done) {
  143. this.docs = {
  144. '/chapter1.tex': {
  145. _id: this.docId1,
  146. lines: ['\\begin{document}', 'Hello world', '\\end{document}'],
  147. },
  148. '/style.bst': {
  149. _id: this.docId2,
  150. lines: ['%Example: \\documentclass{article}'],
  151. },
  152. }
  153. this.ProjectEntityHandler.getAllDocs = sinon
  154. .stub()
  155. .callsArgWith(1, null, this.docs)
  156. return this.ProjectRootDocManager.setRootDocAutomatically(
  157. this.project_id,
  158. done
  159. )
  160. })
  161. it('should not set the root doc to the doc containing a documentclass', function () {
  162. return this.ProjectEntityUpdateHandler.setRootDoc.called.should.equal(
  163. false
  164. )
  165. })
  166. })
  167. })
  168. describe('findRootDocFileFromDirectory', function () {
  169. beforeEach(function () {
  170. this.fs.readFile
  171. .withArgs('/foo/a.tex')
  172. .callsArgWith(2, null, 'Hello World!')
  173. this.fs.readFile
  174. .withArgs('/foo/b.tex')
  175. .callsArgWith(2, null, "I'm a little teapot, get me out of here.")
  176. this.fs.readFile
  177. .withArgs('/foo/main.tex')
  178. .callsArgWith(2, null, "Help, I'm trapped in a unit testing factory")
  179. this.fs.readFile
  180. .withArgs('/foo/c.tex')
  181. .callsArgWith(2, null, 'Tomato, tomahto.')
  182. this.fs.readFile
  183. .withArgs('/foo/a/a.tex')
  184. .callsArgWith(2, null, 'Potato? Potahto. Potootee!')
  185. return (this.documentclassContent = '% test\n\\documentclass\n% test')
  186. })
  187. describe('when there is a file in a subfolder', function () {
  188. beforeEach(function () {
  189. // have to splice globbyFiles weirdly because of the way the stubbed globby method handles references
  190. return this.globbyFiles.splice(
  191. 0,
  192. this.globbyFiles.length,
  193. 'c.tex',
  194. 'a.tex',
  195. 'a/a.tex',
  196. 'b.tex'
  197. )
  198. })
  199. it('processes the root folder files first, and then the subfolder, in alphabetical order', function (done) {
  200. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  201. '/foo',
  202. (error, path) => {
  203. expect(error).not.to.exist
  204. expect(path).not.to.exist
  205. sinon.assert.callOrder(
  206. this.fs.readFile.withArgs('/foo/a.tex'),
  207. this.fs.readFile.withArgs('/foo/b.tex'),
  208. this.fs.readFile.withArgs('/foo/c.tex'),
  209. this.fs.readFile.withArgs('/foo/a/a.tex')
  210. )
  211. return done()
  212. }
  213. )
  214. })
  215. it('processes smaller files first', function (done) {
  216. this.fs.stat.withArgs('/foo/c.tex').callsArgWith(1, null, { size: 1 })
  217. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  218. '/foo',
  219. (error, path) => {
  220. expect(error).not.to.exist
  221. expect(path).not.to.exist
  222. sinon.assert.callOrder(
  223. this.fs.readFile.withArgs('/foo/c.tex'),
  224. this.fs.readFile.withArgs('/foo/a.tex'),
  225. this.fs.readFile.withArgs('/foo/b.tex'),
  226. this.fs.readFile.withArgs('/foo/a/a.tex')
  227. )
  228. return done()
  229. }
  230. )
  231. })
  232. })
  233. describe('when main.tex contains a documentclass', function () {
  234. beforeEach(function () {
  235. return this.fs.readFile
  236. .withArgs('/foo/main.tex')
  237. .callsArgWith(2, null, this.documentclassContent)
  238. })
  239. it('returns main.tex', function (done) {
  240. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  241. '/foo',
  242. (error, path, content) => {
  243. expect(error).not.to.exist
  244. expect(path).to.equal('main.tex')
  245. expect(content).to.equal(this.documentclassContent)
  246. return done()
  247. }
  248. )
  249. })
  250. it('processes main.text first and stops processing when it finds the content', function (done) {
  251. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  252. '/foo',
  253. () => {
  254. expect(this.fs.readFile).to.be.calledWith('/foo/main.tex')
  255. expect(this.fs.readFile).not.to.be.calledWith('/foo/a.tex')
  256. return done()
  257. }
  258. )
  259. })
  260. })
  261. describe('when a.tex contains a documentclass', function () {
  262. beforeEach(function () {
  263. return this.fs.readFile
  264. .withArgs('/foo/a.tex')
  265. .callsArgWith(2, null, this.documentclassContent)
  266. })
  267. it('returns a.tex', function (done) {
  268. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  269. '/foo',
  270. (error, path, content) => {
  271. expect(error).not.to.exist
  272. expect(path).to.equal('a.tex')
  273. expect(content).to.equal(this.documentclassContent)
  274. return done()
  275. }
  276. )
  277. })
  278. it('processes main.text first and stops processing when it finds the content', function (done) {
  279. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  280. '/foo',
  281. () => {
  282. expect(this.fs.readFile).to.be.calledWith('/foo/main.tex')
  283. expect(this.fs.readFile).to.be.calledWith('/foo/a.tex')
  284. expect(this.fs.readFile).not.to.be.calledWith('/foo/b.tex')
  285. return done()
  286. }
  287. )
  288. })
  289. })
  290. describe('when there is no documentclass', function () {
  291. it('returns null with no error', function (done) {
  292. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  293. '/foo',
  294. (error, path, content) => {
  295. expect(error).not.to.exist
  296. expect(path).not.to.exist
  297. expect(content).not.to.exist
  298. return done()
  299. }
  300. )
  301. })
  302. it('processes all the files', function (done) {
  303. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  304. '/foo',
  305. () => {
  306. expect(this.fs.readFile).to.be.calledWith('/foo/main.tex')
  307. expect(this.fs.readFile).to.be.calledWith('/foo/a.tex')
  308. expect(this.fs.readFile).to.be.calledWith('/foo/b.tex')
  309. return done()
  310. }
  311. )
  312. })
  313. })
  314. describe('when there is an error reading a file', function () {
  315. beforeEach(function () {
  316. return this.fs.readFile
  317. .withArgs('/foo/a.tex')
  318. .callsArgWith(2, new Error('something went wrong'))
  319. })
  320. it('returns an error', function (done) {
  321. return this.ProjectRootDocManager.findRootDocFileFromDirectory(
  322. '/foo',
  323. (error, path, content) => {
  324. expect(error).to.exist
  325. expect(path).not.to.exist
  326. expect(content).not.to.exist
  327. return done()
  328. }
  329. )
  330. })
  331. })
  332. })
  333. describe('setRootDocFromName', function () {
  334. describe('when there is a suitable root doc', function () {
  335. beforeEach(function (done) {
  336. this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
  337. .stub()
  338. .callsArgWith(1, null, this.docPaths)
  339. this.ProjectEntityUpdateHandler.setRootDoc = sinon
  340. .stub()
  341. .callsArgWith(2)
  342. return this.ProjectRootDocManager.setRootDocFromName(
  343. this.project_id,
  344. '/main.tex',
  345. done
  346. )
  347. })
  348. it('should check the docs of the project', function () {
  349. return this.ProjectEntityHandler.getAllDocPathsFromProjectById
  350. .calledWith(this.project_id)
  351. .should.equal(true)
  352. })
  353. it('should set the root doc to main.tex', function () {
  354. return this.ProjectEntityUpdateHandler.setRootDoc
  355. .calledWith(this.project_id, this.docId2.toString())
  356. .should.equal(true)
  357. })
  358. })
  359. describe('when there is a suitable root doc but the leading slash is missing', function () {
  360. beforeEach(function (done) {
  361. this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
  362. .stub()
  363. .callsArgWith(1, null, this.docPaths)
  364. this.ProjectEntityUpdateHandler.setRootDoc = sinon
  365. .stub()
  366. .callsArgWith(2)
  367. return this.ProjectRootDocManager.setRootDocFromName(
  368. this.project_id,
  369. 'main.tex',
  370. done
  371. )
  372. })
  373. it('should check the docs of the project', function () {
  374. return this.ProjectEntityHandler.getAllDocPathsFromProjectById
  375. .calledWith(this.project_id)
  376. .should.equal(true)
  377. })
  378. it('should set the root doc to main.tex', function () {
  379. return this.ProjectEntityUpdateHandler.setRootDoc
  380. .calledWith(this.project_id, this.docId2.toString())
  381. .should.equal(true)
  382. })
  383. })
  384. describe('when there is a suitable root doc with a basename match', function () {
  385. beforeEach(function (done) {
  386. this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
  387. .stub()
  388. .callsArgWith(1, null, this.docPaths)
  389. this.ProjectEntityUpdateHandler.setRootDoc = sinon
  390. .stub()
  391. .callsArgWith(2)
  392. return this.ProjectRootDocManager.setRootDocFromName(
  393. this.project_id,
  394. 'chapter1a.tex',
  395. done
  396. )
  397. })
  398. it('should check the docs of the project', function () {
  399. return this.ProjectEntityHandler.getAllDocPathsFromProjectById
  400. .calledWith(this.project_id)
  401. .should.equal(true)
  402. })
  403. it('should set the root doc using the basename', function () {
  404. return this.ProjectEntityUpdateHandler.setRootDoc
  405. .calledWith(this.project_id, this.docId3.toString())
  406. .should.equal(true)
  407. })
  408. })
  409. describe('when there is a suitable root doc but the filename is in quotes', function () {
  410. beforeEach(function (done) {
  411. this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
  412. .stub()
  413. .callsArgWith(1, null, this.docPaths)
  414. this.ProjectEntityUpdateHandler.setRootDoc = sinon
  415. .stub()
  416. .callsArgWith(2)
  417. return this.ProjectRootDocManager.setRootDocFromName(
  418. this.project_id,
  419. "'main.tex'",
  420. done
  421. )
  422. })
  423. it('should check the docs of the project', function () {
  424. return this.ProjectEntityHandler.getAllDocPathsFromProjectById
  425. .calledWith(this.project_id)
  426. .should.equal(true)
  427. })
  428. it('should set the root doc to main.tex', function () {
  429. return this.ProjectEntityUpdateHandler.setRootDoc
  430. .calledWith(this.project_id, this.docId2.toString())
  431. .should.equal(true)
  432. })
  433. })
  434. describe('when there is no suitable root doc', function () {
  435. beforeEach(function (done) {
  436. this.ProjectEntityHandler.getAllDocPathsFromProjectById = sinon
  437. .stub()
  438. .callsArgWith(1, null, this.docPaths)
  439. this.ProjectEntityUpdateHandler.setRootDoc = sinon
  440. .stub()
  441. .callsArgWith(2)
  442. return this.ProjectRootDocManager.setRootDocFromName(
  443. this.project_id,
  444. 'other.tex',
  445. done
  446. )
  447. })
  448. it('should not set the root doc', function () {
  449. return this.ProjectEntityUpdateHandler.setRootDoc.called.should.equal(
  450. false
  451. )
  452. })
  453. })
  454. })
  455. describe('ensureRootDocumentIsSet', function () {
  456. beforeEach(function () {
  457. this.project = {}
  458. this.ProjectGetter.getProject = sinon
  459. .stub()
  460. .callsArgWith(2, null, this.project)
  461. return (this.ProjectRootDocManager.setRootDocAutomatically = sinon
  462. .stub()
  463. .callsArgWith(1, null))
  464. })
  465. describe('when the root doc is set', function () {
  466. beforeEach(function () {
  467. this.project.rootDoc_id = this.docId2
  468. return this.ProjectRootDocManager.ensureRootDocumentIsSet(
  469. this.project_id,
  470. this.callback
  471. )
  472. })
  473. it('should find the project fetching only the rootDoc_id field', function () {
  474. return this.ProjectGetter.getProject
  475. .calledWith(this.project_id, { rootDoc_id: 1 })
  476. .should.equal(true)
  477. })
  478. it('should not try to update the project rootDoc_id', function () {
  479. return this.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
  480. false
  481. )
  482. })
  483. it('should call the callback', function () {
  484. return this.callback.called.should.equal(true)
  485. })
  486. })
  487. describe('when the root doc is not set', function () {
  488. beforeEach(function () {
  489. return this.ProjectRootDocManager.ensureRootDocumentIsSet(
  490. this.project_id,
  491. this.callback
  492. )
  493. })
  494. it('should find the project with only the rootDoc_id field', function () {
  495. return this.ProjectGetter.getProject
  496. .calledWith(this.project_id, { rootDoc_id: 1 })
  497. .should.equal(true)
  498. })
  499. it('should update the project rootDoc_id', function () {
  500. return this.ProjectRootDocManager.setRootDocAutomatically
  501. .calledWith(this.project_id)
  502. .should.equal(true)
  503. })
  504. it('should call the callback', function () {
  505. return this.callback.called.should.equal(true)
  506. })
  507. })
  508. describe('when the project does not exist', function () {
  509. beforeEach(function () {
  510. this.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
  511. return this.ProjectRootDocManager.ensureRootDocumentIsSet(
  512. this.project_id,
  513. this.callback
  514. )
  515. })
  516. it('should call the callback with an error', function () {
  517. return this.callback
  518. .calledWith(
  519. sinon.match
  520. .instanceOf(Error)
  521. .and(sinon.match.has('message', 'project not found'))
  522. )
  523. .should.equal(true)
  524. })
  525. })
  526. })
  527. describe('ensureRootDocumentIsValid', function () {
  528. beforeEach(function () {
  529. this.project = {}
  530. this.ProjectGetter.getProject = sinon
  531. .stub()
  532. .callsArgWith(2, null, this.project)
  533. this.ProjectGetter.getProjectWithoutDocLines = sinon
  534. .stub()
  535. .callsArgWith(1, null, this.project)
  536. this.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().yields()
  537. this.ProjectEntityUpdateHandler.unsetRootDoc = sinon.stub().yields()
  538. this.ProjectRootDocManager.setRootDocAutomatically = sinon
  539. .stub()
  540. .callsArgWith(1, null)
  541. })
  542. describe('when the root doc is set', function () {
  543. describe('when the root doc is valid', function () {
  544. beforeEach(function () {
  545. this.project.rootDoc_id = this.docId2
  546. this.ProjectEntityHandler.getDocPathFromProjectByDocId = sinon
  547. .stub()
  548. .callsArgWith(2, null, this.docPaths[this.docId2])
  549. return this.ProjectRootDocManager.ensureRootDocumentIsValid(
  550. this.project_id,
  551. this.callback
  552. )
  553. })
  554. it('should find the project without doc lines', function () {
  555. return this.ProjectGetter.getProjectWithoutDocLines
  556. .calledWith(this.project_id)
  557. .should.equal(true)
  558. })
  559. it('should not try to update the project rootDoc_id', function () {
  560. return this.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
  561. false
  562. )
  563. })
  564. it('should call the callback', function () {
  565. return this.callback.called.should.equal(true)
  566. })
  567. })
  568. describe('when the root doc is not valid', function () {
  569. beforeEach(function () {
  570. this.project.rootDoc_id = new ObjectId()
  571. this.ProjectEntityHandler.getDocPathFromProjectByDocId = sinon
  572. .stub()
  573. .callsArgWith(2, null, null)
  574. return this.ProjectRootDocManager.ensureRootDocumentIsValid(
  575. this.project_id,
  576. this.callback
  577. )
  578. })
  579. it('should find the project without doc lines', function () {
  580. return this.ProjectGetter.getProjectWithoutDocLines
  581. .calledWith(this.project_id)
  582. .should.equal(true)
  583. })
  584. it('should unset the root doc', function () {
  585. return this.ProjectEntityUpdateHandler.unsetRootDoc
  586. .calledWith(this.project_id)
  587. .should.equal(true)
  588. })
  589. it('should try to find a new rootDoc', function () {
  590. return this.ProjectRootDocManager.setRootDocAutomatically.called.should.equal(
  591. true
  592. )
  593. })
  594. it('should call the callback', function () {
  595. return this.callback.called.should.equal(true)
  596. })
  597. })
  598. })
  599. describe('when the root doc is not set', function () {
  600. beforeEach(function () {
  601. return this.ProjectRootDocManager.ensureRootDocumentIsValid(
  602. this.project_id,
  603. this.callback
  604. )
  605. })
  606. it('should find the project without doc lines', function () {
  607. return this.ProjectGetter.getProjectWithoutDocLines
  608. .calledWith(this.project_id)
  609. .should.equal(true)
  610. })
  611. it('should update the project rootDoc_id', function () {
  612. return this.ProjectRootDocManager.setRootDocAutomatically
  613. .calledWith(this.project_id)
  614. .should.equal(true)
  615. })
  616. it('should call the callback', function () {
  617. return this.callback.called.should.equal(true)
  618. })
  619. })
  620. describe('when the project does not exist', function () {
  621. beforeEach(function () {
  622. this.ProjectGetter.getProjectWithoutDocLines = sinon
  623. .stub()
  624. .callsArgWith(1, null, null)
  625. return this.ProjectRootDocManager.ensureRootDocumentIsValid(
  626. this.project_id,
  627. this.callback
  628. )
  629. })
  630. it('should call the callback with an error', function () {
  631. return this.callback
  632. .calledWith(
  633. sinon.match
  634. .instanceOf(Error)
  635. .and(sinon.match.has('message', 'project not found'))
  636. )
  637. .should.equal(true)
  638. })
  639. })
  640. })
  641. })