TpdsControllerTests.coffee 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. modulePath = require('path').join __dirname, '../../../../app/js/Features/ThirdPartyDataStore/TpdsController.js'
  5. describe 'third party data store', ->
  6. beforeEach ->
  7. @updateHandler = {}
  8. @controller = SandboxedModule.require modulePath, requires:
  9. './TpdsUpdateHandler':@updateHandler
  10. 'logger-sharelatex':
  11. log:->
  12. err:->
  13. @user_id = "dsad29jlkjas"
  14. describe 'getting an update', ->
  15. it 'should process the update with the update reciver', (done)->
  16. path = "/projectName/here.txt"
  17. req =
  18. pause:->
  19. params:{0:path, "user_id":@user_id}
  20. session:
  21. destroy:->
  22. @updateHandler.newUpdate = sinon.stub().callsArg(5)
  23. res = send: =>
  24. @updateHandler.newUpdate.calledWith(@user_id, "projectName","/here.txt", req).should.equal true
  25. done()
  26. @controller.mergeUpdate req, res
  27. describe 'getting a delete update', ->
  28. it 'should process the delete with the update reciver', (done)->
  29. path = "/projectName/here.txt"
  30. req =
  31. params:{0:path, "user_id":@user_id}
  32. session:
  33. destroy:->
  34. @updateHandler.deleteUpdate = sinon.stub().callsArg(4)
  35. res = send: =>
  36. @updateHandler.deleteUpdate.calledWith(@user_id, "projectName", "/here.txt").should.equal true
  37. done()
  38. @controller.deleteUpdate req, res
  39. describe 'parseParams', ->
  40. it 'should take the project name off the start and replace with slash', ->
  41. path = "noSlashHere"
  42. req = params:{0:path, user_id:@user_id}
  43. result = @controller.parseParams(req)
  44. result.user_id.should.equal @user_id
  45. result.filePath.should.equal "/"
  46. result.projectName.should.equal path
  47. it 'should take the project name off the start and return it with no slashes in', ->
  48. path = "/project/file.tex"
  49. req = params:{0:path, user_id:@user_id}
  50. result = @controller.parseParams(req)
  51. result.user_id.should.equal @user_id
  52. result.filePath.should.equal "/file.tex"
  53. result.projectName.should.equal "project"
  54. it 'should take the project name of and return a slash for the file path', ->
  55. path = "/project_name"
  56. req = params:{0:path, user_id:@user_id}
  57. result = @controller.parseParams(req)
  58. result.projectName.should.equal "project_name"
  59. result.filePath.should.equal "/"