ProjectDeleterTests.coffee 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. should = require('chai').should()
  2. modulePath = "../../../../app/js/Features/Project/ProjectDeleter"
  3. SandboxedModule = require('sandboxed-module')
  4. sinon = require('sinon')
  5. describe 'Project deleter', ->
  6. beforeEach ->
  7. @project_id = "12312"
  8. @project =
  9. _id: @project_id
  10. rootFolder:[]
  11. collaberator_refs:["collab1", "collab2"]
  12. readOnly_refs:["readOnly1", "readOnly2"]
  13. owner_ref:"owner ref here"
  14. @Project =
  15. update: sinon.stub().callsArgWith(3)
  16. remove: sinon.stub().callsArgWith(1)
  17. findById: sinon.stub().callsArgWith(1, null, @project)
  18. applyToAllFilesRecursivly: sinon.stub()
  19. @documentUpdaterHandler =
  20. flushProjectToMongoAndDelete:sinon.stub().callsArgWith(1)
  21. @AutomaticSnapshotManager =
  22. unmarkProjectAsUpdated:sinon.stub().callsArgWith(1)
  23. @editorController = notifyUsersProjectHasBeenDeletedOrRenamed : sinon.stub().callsArgWith(1)
  24. @TagsHandler =
  25. removeProjectFromAllTags: sinon.stub().callsArgWith(2)
  26. @deleter = SandboxedModule.require modulePath, requires:
  27. "../Editor/EditorController": @editorController
  28. '../../models/Project':{Project:@Project}
  29. '../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler
  30. '../Versioning/AutomaticSnapshotManager':@AutomaticSnapshotManager
  31. "../Tags/TagsHandler":@TagsHandler
  32. 'logger-sharelatex':
  33. log:->
  34. describe "mark as deleted by external source", ->
  35. project_id = 1234
  36. it 'should update the project with the flag set to true', (done)->
  37. @deleter.markAsDeletedByExternalSource project_id, =>
  38. conditions = {_id:project_id}
  39. update = {deletedByExternalDataSource:true}
  40. @Project.update.calledWith(conditions, update).should.equal true
  41. done()
  42. it 'should tell the editor controler so users are notified', (done)->
  43. @deleter.markAsDeletedByExternalSource project_id, =>
  44. @editorController.notifyUsersProjectHasBeenDeletedOrRenamed.calledWith(project_id).should.equal true
  45. done()
  46. describe "deleteUsersProjects", ->
  47. it "should remove all the projects owned by the user_id", (done)->
  48. user_id = 1234
  49. @deleter.deleteUsersProjects user_id, =>
  50. @Project.remove.calledWith(owner_ref:user_id).should.equal true
  51. done()
  52. describe "deleteProject", ->
  53. beforeEach ->
  54. @Project.update.callsArgWith(2)
  55. it "should flushProjectToMongoAndDelete in doc updater", (done)->
  56. @deleter.deleteProject @project_id, =>
  57. @documentUpdaterHandler.flushProjectToMongoAndDelete.calledWith(@project_id).should.equal true
  58. done()
  59. it "should remove the project", (done)->
  60. @deleter.deleteProject @project_id, =>
  61. @Project.update.calledWith({
  62. _id:@project_id
  63. }, {
  64. $set: { archived: true }
  65. }).should.equal true
  66. done()
  67. it "should removeProjectFromAllTags", (done)->
  68. @deleter.deleteProject @project_id, =>
  69. @TagsHandler.removeProjectFromAllTags.calledWith(@project.owner_ref, @project_id).should.equal true
  70. @TagsHandler.removeProjectFromAllTags.calledWith(@project.collaberator_refs[0], @project_id).should.equal true
  71. @TagsHandler.removeProjectFromAllTags.calledWith(@project.collaberator_refs[1], @project_id).should.equal true
  72. @TagsHandler.removeProjectFromAllTags.calledWith(@project.readOnly_refs[0], @project_id).should.equal true
  73. @TagsHandler.removeProjectFromAllTags.calledWith(@project.readOnly_refs[1], @project_id).should.equal true
  74. done()