ProjectDeleterTests.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. const modulePath = '../../../../app/src/Features/Project/ProjectDeleter'
  2. const SandboxedModule = require('sandboxed-module')
  3. const sinon = require('sinon')
  4. const chai = require('chai')
  5. const { expect } = chai
  6. const tk = require('timekeeper')
  7. const moment = require('moment')
  8. const { Project } = require('../helpers/models/Project')
  9. const { DeletedProject } = require('../helpers/models/DeletedProject')
  10. const { ObjectId } = require('mongodb')
  11. const Errors = require('../../../../app/src/Features/Errors/Errors')
  12. describe('ProjectDeleter', function() {
  13. beforeEach(function() {
  14. tk.freeze(Date.now())
  15. this.ip = '192.170.18.1'
  16. this.project = dummyProject()
  17. this.user = {
  18. _id: '588f3ddae8ebc1bac07c9fa4',
  19. first_name: 'bjkdsjfk',
  20. features: {}
  21. }
  22. this.doc = {
  23. _id: '5bd975f54f62e803cb8a8fec',
  24. lines: ['a bunch of lines', 'for a sunny day', 'in London town'],
  25. ranges: {},
  26. project_id: '5cf9270b4eff6e186cf8b05e'
  27. }
  28. this.deletedProjects = [
  29. {
  30. _id: '5cf7f145c1401f0ca0eb1aaa',
  31. deleterData: {
  32. _id: '5cf7f145c1401f0ca0eb1aac',
  33. deletedAt: moment()
  34. .subtract(95, 'days')
  35. .toDate(),
  36. deleterId: '588f3ddae8ebc1bac07c9fa4',
  37. deleterIpAddress: '172.19.0.1',
  38. deletedProjectId: '5cf9270b4eff6e186cf8b05e'
  39. },
  40. project: {
  41. _id: '5cf9270b4eff6e186cf8b05e'
  42. }
  43. },
  44. {
  45. _id: '5cf8eb11c1401f0ca0eb1ad7',
  46. deleterData: {
  47. _id: '5b74360c0fbe57011ae9938f',
  48. deletedAt: moment()
  49. .subtract(95, 'days')
  50. .toDate(),
  51. deleterId: '588f3ddae8ebc1bac07c9fa4',
  52. deleterIpAddress: '172.20.0.1',
  53. deletedProjectId: '5cf8f95a0c87371362c23919'
  54. },
  55. project: {
  56. _id: '5cf8f95a0c87371362c23919'
  57. }
  58. }
  59. ]
  60. this.DocumentUpdaterHandler = {
  61. promises: {
  62. flushProjectToMongoAndDelete: sinon.stub().resolves()
  63. }
  64. }
  65. this.EditorRealTimeController = {
  66. emitToRoom: sinon.stub()
  67. }
  68. this.TagsHandler = {
  69. promises: {
  70. removeProjectFromAllTags: sinon.stub().resolves()
  71. }
  72. }
  73. this.CollaboratorsHandler = {
  74. promises: {
  75. removeUserFromAllProjects: sinon.stub().resolves()
  76. }
  77. }
  78. this.CollaboratorsGetter = {
  79. promises: {
  80. getMemberIds: sinon
  81. .stub()
  82. .withArgs(this.project._id)
  83. .resolves(['member-id-1', 'member-id-2'])
  84. }
  85. }
  86. this.logger = {
  87. err: sinon.stub(),
  88. log: sinon.stub(),
  89. warn: sinon.stub()
  90. }
  91. this.ProjectDetailsHandler = {
  92. promises: {
  93. generateUniqueName: sinon.stub().resolves(this.project.name)
  94. }
  95. }
  96. this.ProjectHelper = {
  97. calculateArchivedArray: sinon.stub()
  98. }
  99. this.db = {
  100. projects: {
  101. insert: sinon.stub().yields()
  102. }
  103. }
  104. this.DocstoreManager = {
  105. promises: {
  106. destroyProject: sinon.stub().resolves()
  107. }
  108. }
  109. this.HistoryManager = {
  110. promises: {
  111. deleteProject: sinon.stub().resolves()
  112. }
  113. }
  114. this.ProjectMock = sinon.mock(Project)
  115. this.DeletedProjectMock = sinon.mock(DeletedProject)
  116. this.FileStoreHandler = {
  117. promises: {
  118. deleteProject: sinon.stub().resolves()
  119. }
  120. }
  121. this.ProjectDeleter = SandboxedModule.require(modulePath, {
  122. requires: {
  123. '../Editor/EditorRealTimeController': this.EditorRealTimeController,
  124. '../../models/Project': { Project: Project },
  125. './ProjectHelper': this.ProjectHelper,
  126. '../../models/DeletedProject': { DeletedProject: DeletedProject },
  127. '../DocumentUpdater/DocumentUpdaterHandler': this
  128. .DocumentUpdaterHandler,
  129. '../Tags/TagsHandler': this.TagsHandler,
  130. '../FileStore/FileStoreHandler': this.FileStoreHandler,
  131. '../Collaborators/CollaboratorsHandler': this.CollaboratorsHandler,
  132. '../Collaborators/CollaboratorsGetter': this.CollaboratorsGetter,
  133. '../Docstore/DocstoreManager': this.DocstoreManager,
  134. './ProjectDetailsHandler': this.ProjectDetailsHandler,
  135. '../../infrastructure/mongojs': { db: this.db, ObjectId },
  136. '../History/HistoryManager': this.HistoryManager,
  137. 'logger-sharelatex': this.logger,
  138. '../Errors/Errors': Errors
  139. },
  140. globals: {
  141. console: console
  142. }
  143. })
  144. })
  145. afterEach(function() {
  146. tk.reset()
  147. this.DeletedProjectMock.restore()
  148. this.ProjectMock.restore()
  149. })
  150. describe('mark as deleted by external source', function() {
  151. beforeEach(function() {
  152. this.ProjectMock.expects('update')
  153. .withArgs(
  154. { _id: this.project._id },
  155. { deletedByExternalDataSource: true }
  156. )
  157. .chain('exec')
  158. .resolves()
  159. })
  160. it('should update the project with the flag set to true', async function() {
  161. await this.ProjectDeleter.promises.markAsDeletedByExternalSource(
  162. this.project._id
  163. )
  164. this.ProjectMock.verify()
  165. })
  166. it('should tell the editor controler so users are notified', async function() {
  167. await this.ProjectDeleter.promises.markAsDeletedByExternalSource(
  168. this.project._id
  169. )
  170. expect(this.EditorRealTimeController.emitToRoom).to.have.been.calledWith(
  171. this.project._id,
  172. 'projectRenamedOrDeletedByExternalSource'
  173. )
  174. })
  175. })
  176. describe('unmarkAsDeletedByExternalSource', function() {
  177. beforeEach(async function() {
  178. this.ProjectMock.expects('update')
  179. .withArgs(
  180. { _id: this.project._id },
  181. { deletedByExternalDataSource: false }
  182. )
  183. .chain('exec')
  184. .resolves()
  185. await this.ProjectDeleter.promises.unmarkAsDeletedByExternalSource(
  186. this.project._id
  187. )
  188. })
  189. it('should remove the flag from the project', function() {
  190. this.ProjectMock.verify()
  191. })
  192. })
  193. describe('deleteUsersProjects', function() {
  194. beforeEach(function() {
  195. this.projects = [dummyProject(), dummyProject()]
  196. this.ProjectMock.expects('find')
  197. .withArgs({ owner_ref: this.user._id })
  198. .chain('exec')
  199. .resolves(this.projects)
  200. for (const project of this.projects) {
  201. this.ProjectMock.expects('findOne')
  202. .withArgs({ _id: project._id })
  203. .chain('exec')
  204. .resolves(project)
  205. this.ProjectMock.expects('remove')
  206. .withArgs({ _id: project._id })
  207. .chain('exec')
  208. .resolves()
  209. this.DeletedProjectMock.expects('update')
  210. .withArgs(
  211. { 'deleterData.deletedProjectId': project._id },
  212. {
  213. project,
  214. deleterData: sinon.match.object
  215. },
  216. { upsert: true }
  217. )
  218. .resolves()
  219. }
  220. })
  221. it('should delete all projects owned by the user', async function() {
  222. await this.ProjectDeleter.promises.deleteUsersProjects(this.user._id)
  223. this.ProjectMock.verify()
  224. this.DeletedProjectMock.verify()
  225. })
  226. it('should remove any collaboration from this user', async function() {
  227. await this.ProjectDeleter.promises.deleteUsersProjects(this.user._id)
  228. sinon.assert.calledWith(
  229. this.CollaboratorsHandler.promises.removeUserFromAllProjects,
  230. this.user._id
  231. )
  232. sinon.assert.calledOnce(
  233. this.CollaboratorsHandler.promises.removeUserFromAllProjects
  234. )
  235. })
  236. })
  237. describe('deleteProject', function() {
  238. beforeEach(function() {
  239. this.deleterData = {
  240. deletedAt: new Date(),
  241. deletedProjectId: this.project._id,
  242. deletedProjectOwnerId: this.project.owner_ref,
  243. deletedProjectCollaboratorIds: this.project.collaberator_refs,
  244. deletedProjectReadOnlyIds: this.project.readOnly_refs,
  245. deletedProjectReadWriteTokenAccessIds: this.project
  246. .tokenAccessReadAndWrite_refs,
  247. deletedProjectReadOnlyTokenAccessIds: this.project
  248. .tokenAccessReadOnly_refs,
  249. deletedProjectReadWriteToken: this.project.tokens.readAndWrite,
  250. deletedProjectReadOnlyToken: this.project.tokens.readOnly,
  251. deletedProjectOverleafId: this.project.overleaf.id,
  252. deletedProjectOverleafHistoryId: this.project.overleaf.history.id,
  253. deletedProjectLastUpdatedAt: this.project.lastUpdated
  254. }
  255. this.ProjectMock.expects('findOne')
  256. .withArgs({ _id: this.project._id })
  257. .chain('exec')
  258. .resolves(this.project)
  259. })
  260. it('should save a DeletedProject with additional deleterData', async function() {
  261. this.deleterData.deleterIpAddress = this.ip
  262. this.deleterData.deleterId = this.user._id
  263. this.ProjectMock.expects('remove')
  264. .chain('exec')
  265. .resolves()
  266. this.DeletedProjectMock.expects('update')
  267. .withArgs(
  268. { 'deleterData.deletedProjectId': this.project._id },
  269. {
  270. project: this.project,
  271. deleterData: this.deleterData
  272. },
  273. { upsert: true }
  274. )
  275. .resolves()
  276. await this.ProjectDeleter.promises.deleteProject(this.project._id, {
  277. deleterUser: this.user,
  278. ipAddress: this.ip
  279. })
  280. this.DeletedProjectMock.verify()
  281. })
  282. it('should flushProjectToMongoAndDelete in doc updater', async function() {
  283. this.ProjectMock.expects('remove')
  284. .chain('exec')
  285. .resolves()
  286. this.DeletedProjectMock.expects('update').resolves()
  287. await this.ProjectDeleter.promises.deleteProject(this.project._id, {
  288. deleterUser: this.user,
  289. ipAddress: this.ip
  290. })
  291. this.DocumentUpdaterHandler.promises.flushProjectToMongoAndDelete
  292. .calledWith(this.project._id)
  293. .should.equal(true)
  294. })
  295. it('should removeProjectFromAllTags', async function() {
  296. this.ProjectMock.expects('remove')
  297. .chain('exec')
  298. .resolves()
  299. this.DeletedProjectMock.expects('update').resolves()
  300. await this.ProjectDeleter.promises.deleteProject(this.project._id)
  301. sinon.assert.calledWith(
  302. this.TagsHandler.promises.removeProjectFromAllTags,
  303. 'member-id-1',
  304. this.project._id
  305. )
  306. sinon.assert.calledWith(
  307. this.TagsHandler.promises.removeProjectFromAllTags,
  308. 'member-id-2',
  309. this.project._id
  310. )
  311. })
  312. it('should remove the project from Mongo', async function() {
  313. this.ProjectMock.expects('remove')
  314. .withArgs({ _id: this.project._id })
  315. .chain('exec')
  316. .resolves()
  317. this.DeletedProjectMock.expects('update').resolves()
  318. await this.ProjectDeleter.promises.deleteProject(this.project._id)
  319. this.ProjectMock.verify()
  320. })
  321. })
  322. describe('expireDeletedProjectsAfterDuration', function() {
  323. beforeEach(async function() {
  324. this.DeletedProjectMock.expects('find')
  325. .withArgs({
  326. 'deleterData.deletedAt': {
  327. $lt: new Date(moment().subtract(90, 'days'))
  328. },
  329. project: {
  330. $ne: null
  331. }
  332. })
  333. .chain('exec')
  334. .resolves(this.deletedProjects)
  335. for (const deletedProject of this.deletedProjects) {
  336. this.DeletedProjectMock.expects('findOne')
  337. .withArgs({
  338. 'deleterData.deletedProjectId': deletedProject.project._id
  339. })
  340. .chain('exec')
  341. .resolves(deletedProject)
  342. this.DeletedProjectMock.expects('update')
  343. .withArgs(
  344. {
  345. _id: deletedProject._id
  346. },
  347. {
  348. $set: {
  349. 'deleterData.deleterIpAddress': null,
  350. project: null
  351. }
  352. }
  353. )
  354. .chain('exec')
  355. .resolves()
  356. }
  357. await this.ProjectDeleter.promises.expireDeletedProjectsAfterDuration()
  358. })
  359. it('should expire projects older than 90 days', function() {
  360. this.DeletedProjectMock.verify()
  361. })
  362. })
  363. describe('expireDeletedProject', function() {
  364. beforeEach(async function() {
  365. this.DeletedProjectMock.expects('update')
  366. .withArgs(
  367. {
  368. _id: this.deletedProjects[0]._id
  369. },
  370. {
  371. $set: {
  372. 'deleterData.deleterIpAddress': null,
  373. project: null
  374. }
  375. }
  376. )
  377. .chain('exec')
  378. .resolves()
  379. this.DeletedProjectMock.expects('findOne')
  380. .withArgs({
  381. 'deleterData.deletedProjectId': this.deletedProjects[0].project._id
  382. })
  383. .chain('exec')
  384. .resolves(this.deletedProjects[0])
  385. await this.ProjectDeleter.promises.expireDeletedProject(
  386. this.deletedProjects[0].project._id
  387. )
  388. })
  389. it('should find the specified deletedProject and remove its project and ip address', function() {
  390. this.DeletedProjectMock.verify()
  391. })
  392. it('should destroy the docs in docstore', function() {
  393. expect(
  394. this.DocstoreManager.promises.destroyProject
  395. ).to.have.been.calledWith(this.deletedProjects[0].project._id)
  396. })
  397. it('should delete the project in project-history', function() {
  398. expect(
  399. this.HistoryManager.promises.deleteProject
  400. ).to.have.been.calledWith(this.deletedProjects[0].project._id)
  401. })
  402. it('should destroy the files in filestore', function() {
  403. expect(
  404. this.FileStoreHandler.promises.deleteProject
  405. ).to.have.been.calledWith(this.deletedProjects[0].project._id)
  406. })
  407. })
  408. describe('archiveProject', function() {
  409. beforeEach(function() {
  410. let archived = [ObjectId(this.user._id)]
  411. this.ProjectHelper.calculateArchivedArray.returns(archived)
  412. this.ProjectMock.expects('findOne')
  413. .withArgs({ _id: this.project._id })
  414. .chain('exec')
  415. .resolves(this.project)
  416. this.ProjectMock.expects('update')
  417. .withArgs(
  418. { _id: this.project._id },
  419. {
  420. $set: { archived: archived },
  421. $pull: { trashed: ObjectId(this.user._id) }
  422. }
  423. )
  424. .resolves()
  425. })
  426. it('should update the project', async function() {
  427. await this.ProjectDeleter.promises.archiveProject(
  428. this.project._id,
  429. this.user._id
  430. )
  431. this.ProjectMock.verify()
  432. })
  433. it('calculates the archived array', async function() {
  434. await this.ProjectDeleter.promises.archiveProject(
  435. this.project._id,
  436. this.user._id
  437. )
  438. expect(this.ProjectHelper.calculateArchivedArray).to.have.been.calledWith(
  439. this.project,
  440. this.user._id,
  441. 'ARCHIVE'
  442. )
  443. })
  444. })
  445. describe('unarchiveProject', function() {
  446. beforeEach(function() {
  447. let archived = [ObjectId(this.user._id)]
  448. this.ProjectHelper.calculateArchivedArray.returns(archived)
  449. this.ProjectMock.expects('findOne')
  450. .withArgs({ _id: this.project._id })
  451. .chain('exec')
  452. .resolves(this.project)
  453. this.ProjectMock.expects('update')
  454. .withArgs({ _id: this.project._id }, { $set: { archived: archived } })
  455. .resolves()
  456. })
  457. it('should update the project', async function() {
  458. await this.ProjectDeleter.promises.unarchiveProject(
  459. this.project._id,
  460. this.user._id
  461. )
  462. this.ProjectMock.verify()
  463. })
  464. it('calculates the archived array', async function() {
  465. await this.ProjectDeleter.promises.unarchiveProject(
  466. this.project._id,
  467. this.user._id
  468. )
  469. expect(this.ProjectHelper.calculateArchivedArray).to.have.been.calledWith(
  470. this.project,
  471. this.user._id,
  472. 'UNARCHIVE'
  473. )
  474. })
  475. })
  476. describe('trashProject', function() {
  477. beforeEach(function() {
  478. let archived = [ObjectId(this.user._id)]
  479. this.ProjectHelper.calculateArchivedArray.returns(archived)
  480. this.ProjectMock.expects('findOne')
  481. .withArgs({ _id: this.project._id })
  482. .chain('exec')
  483. .resolves(this.project)
  484. this.ProjectMock.expects('update')
  485. .withArgs(
  486. { _id: this.project._id },
  487. {
  488. $addToSet: { trashed: ObjectId(this.user._id) },
  489. $set: { archived: archived }
  490. }
  491. )
  492. .resolves()
  493. })
  494. it('should update the project', async function() {
  495. await this.ProjectDeleter.promises.trashProject(
  496. this.project._id,
  497. this.user._id
  498. )
  499. this.ProjectMock.verify()
  500. })
  501. it('unarchives the project', async function() {
  502. await this.ProjectDeleter.promises.trashProject(
  503. this.project._id,
  504. this.user._id
  505. )
  506. expect(this.ProjectHelper.calculateArchivedArray).to.have.been.calledWith(
  507. this.project,
  508. this.user._id,
  509. 'UNARCHIVE'
  510. )
  511. })
  512. })
  513. describe('untrashProject', function() {
  514. beforeEach(function() {
  515. this.ProjectMock.expects('findOne')
  516. .withArgs({ _id: this.project._id })
  517. .chain('exec')
  518. .resolves(this.project)
  519. this.ProjectMock.expects('update')
  520. .withArgs(
  521. { _id: this.project._id },
  522. { $pull: { trashed: ObjectId(this.user._id) } }
  523. )
  524. .resolves()
  525. })
  526. it('should update the project', async function() {
  527. await this.ProjectDeleter.promises.untrashProject(
  528. this.project._id,
  529. this.user._id
  530. )
  531. this.ProjectMock.verify()
  532. })
  533. })
  534. describe('restoreProject', function() {
  535. beforeEach(function() {
  536. this.ProjectMock.expects('update')
  537. .withArgs(
  538. {
  539. _id: this.project._id
  540. },
  541. {
  542. $unset: { archived: true }
  543. }
  544. )
  545. .chain('exec')
  546. .resolves()
  547. })
  548. it('should unset the archive attribute', async function() {
  549. await this.ProjectDeleter.promises.restoreProject(this.project._id)
  550. })
  551. })
  552. describe('undeleteProject', function() {
  553. beforeEach(function() {
  554. this.deletedProject = {
  555. _id: 'deleted',
  556. project: this.project,
  557. deleterData: {
  558. deletedProjectId: this.project._id,
  559. deletedProjectOwnerId: this.project.owner_ref
  560. }
  561. }
  562. this.purgedProject = {
  563. _id: 'purged',
  564. deleterData: {
  565. deletedProjectId: 'purgedProject',
  566. deletedProjectOwnerId: 'potato'
  567. }
  568. }
  569. this.DeletedProjectMock.expects('findOne')
  570. .withArgs({ 'deleterData.deletedProjectId': this.project._id })
  571. .chain('exec')
  572. .resolves(this.deletedProject)
  573. this.DeletedProjectMock.expects('findOne')
  574. .withArgs({ 'deleterData.deletedProjectId': 'purgedProject' })
  575. .chain('exec')
  576. .resolves(this.purgedProject)
  577. this.DeletedProjectMock.expects('findOne')
  578. .withArgs({ 'deleterData.deletedProjectId': 'wombat' })
  579. .chain('exec')
  580. .resolves(null)
  581. this.DeletedProjectMock.expects('deleteOne')
  582. .chain('exec')
  583. .resolves()
  584. })
  585. it('should return not found if the project does not exist', async function() {
  586. await expect(
  587. this.ProjectDeleter.promises.undeleteProject('wombat')
  588. ).to.be.rejectedWith(Errors.NotFoundError, 'project_not_found')
  589. })
  590. it('should return not found if the project has been expired', async function() {
  591. await expect(
  592. this.ProjectDeleter.promises.undeleteProject('purgedProject')
  593. ).to.be.rejectedWith(Errors.NotFoundError, 'project_too_old_to_restore')
  594. })
  595. it('should insert the project into the collection', async function() {
  596. await this.ProjectDeleter.promises.undeleteProject(this.project._id)
  597. sinon.assert.calledWith(
  598. this.db.projects.insert,
  599. sinon.match({
  600. _id: this.project._id,
  601. name: this.project.name
  602. })
  603. )
  604. })
  605. it('should clear the archive bit', async function() {
  606. this.project.archived = true
  607. await this.ProjectDeleter.promises.undeleteProject(this.project._id)
  608. sinon.assert.calledWith(
  609. this.db.projects.insert,
  610. sinon.match({ archived: undefined })
  611. )
  612. })
  613. it('should generate a unique name for the project', async function() {
  614. await this.ProjectDeleter.promises.undeleteProject(this.project._id)
  615. sinon.assert.calledWith(
  616. this.ProjectDetailsHandler.promises.generateUniqueName,
  617. this.project.owner_ref
  618. )
  619. })
  620. it('should add a suffix to the project name', async function() {
  621. await this.ProjectDeleter.promises.undeleteProject(this.project._id)
  622. sinon.assert.calledWith(
  623. this.ProjectDetailsHandler.promises.generateUniqueName,
  624. this.project.owner_ref,
  625. this.project.name + ' (Restored)'
  626. )
  627. })
  628. it('should remove the DeletedProject', async function() {
  629. // need to change the mock just to include the methods we want
  630. this.DeletedProjectMock.restore()
  631. this.DeletedProjectMock = sinon.mock(DeletedProject)
  632. this.DeletedProjectMock.expects('findOne')
  633. .withArgs({ 'deleterData.deletedProjectId': this.project._id })
  634. .chain('exec')
  635. .resolves(this.deletedProject)
  636. this.DeletedProjectMock.expects('deleteOne')
  637. .withArgs({ _id: 'deleted' })
  638. .chain('exec')
  639. .resolves()
  640. await this.ProjectDeleter.promises.undeleteProject(this.project._id)
  641. this.DeletedProjectMock.verify()
  642. })
  643. })
  644. })
  645. function dummyProject() {
  646. return {
  647. _id: new ObjectId(),
  648. lastUpdated: new Date(),
  649. rootFolder: [],
  650. collaberator_refs: [new ObjectId(), new ObjectId()],
  651. readOnly_refs: [new ObjectId(), new ObjectId()],
  652. tokenAccessReadAndWrite_refs: [new ObjectId(), new ObjectId()],
  653. tokenAccessReadOnly_refs: [new ObjectId(), new ObjectId()],
  654. owner_ref: new ObjectId(),
  655. tokens: {
  656. readOnly: 'wombat',
  657. readAndWrite: 'potato'
  658. },
  659. overleaf: {
  660. id: 1234,
  661. history: {
  662. id: 5678
  663. }
  664. },
  665. name: 'a very scientific analysis of spooky ghosts'
  666. }
  667. }