TpdsUpdateHandlerTests.coffee 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. modulePath = require('path').join __dirname, '../../../../app/js/Features/ThirdPartyDataStore/TpdsUpdateHandler.js'
  5. describe 'TpdsUpdateHandler', ->
  6. beforeEach ->
  7. @requestQueuer = {}
  8. @updateMerger =
  9. deleteUpdate: (user_id, path, cb)->cb()
  10. mergeUpdate:(user_id, path, update, cb)->cb()
  11. @editorController = {}
  12. @project_id = "dsjajilknaksdn"
  13. @project = {_id:@project_id, name:"projectNameHere"}
  14. @projectLocator = findUsersProjectByName:sinon.stub().callsArgWith(2, null, @project)
  15. @projectCreationHandler =
  16. createBlankProject : sinon.stub().callsArgWith(2, null, @project)
  17. @projectDeleter = {markAsDeletedByExternalSource:sinon.stub().callsArgWith(1)}
  18. @rootDocManager = setRootDocAutomatically:sinon.stub()
  19. @handler = SandboxedModule.require modulePath, requires:
  20. './UpdateMerger': @updateMerger
  21. './Editor/EditorController': @editorController
  22. '../Project/ProjectLocator': @projectLocator
  23. '../Project/ProjectCreationHandler':@projectCreationHandler
  24. '../Project/ProjectDeleter': @projectDeleter
  25. "../Project/ProjectRootDocManager" : @rootDocManager
  26. 'logger-sharelatex': log:->
  27. @user_id = "dsad29jlkjas"
  28. @source = "dropbox"
  29. describe 'getting an update', ->
  30. it 'should send the update to the update merger', (done)->
  31. path = "/path/here"
  32. update = {}
  33. @updateMerger.mergeUpdate = sinon.stub()
  34. @updateMerger.mergeUpdate.withArgs(@project_id, path, update).callsArg(3)
  35. @handler.newUpdate @user_id, @project.name, path, update, =>
  36. @projectCreationHandler.createBlankProject.called.should.equal false
  37. done()
  38. it 'should create a new project if one does not already exit', (done)->
  39. @projectLocator.findUsersProjectByName = sinon.stub().callsArgWith(2)
  40. path = "/"
  41. @handler.newUpdate @user_id, @project.name, path, {}, =>
  42. @projectCreationHandler.createBlankProject.calledWith(@user_id, @project.name).should.equal true
  43. done()
  44. it 'should set the root doc automatically if a new project is created', (done)->
  45. @projectLocator.findUsersProjectByName = sinon.stub().callsArgWith(2)
  46. @handler._rootDocTimeoutLength = 0
  47. path = "/"
  48. @handler.newUpdate @user_id, @project.name, path, {}, =>
  49. setTimeout (=>
  50. @rootDocManager.setRootDocAutomatically.calledWith(@project._id).should.equal true
  51. done()
  52. ), 1
  53. describe 'getting a delete :', ->
  54. it 'should call deleteEntity in the collaberation manager', (done)->
  55. path = "/delete/this"
  56. update = {}
  57. @updateMerger.deleteUpdate = sinon.stub().callsArg(2)
  58. @handler.deleteUpdate @user_id, @project.name, path, =>
  59. @projectDeleter.markAsDeletedByExternalSource.calledWith(@project._id).should.equal false
  60. @updateMerger.deleteUpdate.calledWith(@project_id, path).should.equal true
  61. done()
  62. it 'should mark the project as deleted by external source if path is a single slash', (done)->
  63. path = "/"
  64. @handler.deleteUpdate @user_id, @project.name, path, =>
  65. @projectDeleter.markAsDeletedByExternalSource.calledWith(@project._id).should.equal true
  66. done()