TpdsUpdateHandlerTests.coffee 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 'third party data store reciver :', ->
  6. beforeEach ->
  7. @requestQueuer = {}
  8. @updateMerger =
  9. deleteUpdate: (user_id, path, sl_req_id, cb)->cb()
  10. mergeUpdate:(user_id, path, update, sl_req_id, 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. describe 'getting an update', ->
  29. it 'should send the update to the update merger', (done)->
  30. path = "/path/here"
  31. update = {}
  32. @updateMerger.mergeUpdate = sinon.stub()
  33. @updateMerger.mergeUpdate.withArgs(@project_id, path, update).callsArg(4)
  34. @handler.newUpdate @user_id, @project.name, path, update, "", =>
  35. @projectCreationHandler.createBlankProject.called.should.equal false
  36. done()
  37. it 'should create a new project if one does not already exit', (done)->
  38. @projectLocator.findUsersProjectByName = sinon.stub().callsArgWith(2)
  39. path = "/"
  40. @handler.newUpdate @user_id, @project.name, path, {}, "", =>
  41. @projectCreationHandler.createBlankProject.calledWith(@user_id, @project.name).should.equal true
  42. done()
  43. it 'should set the root doc automatically if a new project is created', (done)->
  44. @projectLocator.findUsersProjectByName = sinon.stub().callsArgWith(2)
  45. @handler._rootDocTimeoutLength = 0
  46. path = "/"
  47. @handler.newUpdate @user_id, @project.name, path, {}, "", =>
  48. setTimeout (=>
  49. @rootDocManager.setRootDocAutomatically.calledWith(@project._id).should.equal true
  50. done()
  51. ), 1
  52. describe 'getting a delete :', ->
  53. it 'should call deleteEntity in the collaberation manager', (done)->
  54. path = "/delete/this"
  55. update = {}
  56. @updateMerger.deleteUpdate = sinon.stub().callsArg(3)
  57. @handler.deleteUpdate @user_id, @project.name,path, "sl_req_id", =>
  58. @projectDeleter.markAsDeletedByExternalSource.calledWith(@project._id).should.equal false
  59. @updateMerger.deleteUpdate.calledWith(@project_id, path).should.equal true
  60. done()
  61. it 'should mark the project as deleted by external source if path is a single slash', (done)->
  62. path = "/"
  63. @handler.deleteUpdate @user_id, @project.name, path, "sl_req_id", =>
  64. @projectDeleter.markAsDeletedByExternalSource.calledWith(@project._id).should.equal true
  65. done()