DropboxUserControllerTests.coffee 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. SandboxedModule = require('sandboxed-module')
  2. assert = require('assert')
  3. require('chai').should()
  4. sinon = require('sinon')
  5. modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxUserController.js'
  6. describe 'DropboxUserController', ->
  7. beforeEach ->
  8. @DropboxHandler =
  9. getDropboxRegisterUrl: sinon.stub()
  10. completeRegistration: sinon.stub()
  11. unlinkAccount: sinon.stub()
  12. @controller = SandboxedModule.require modulePath, requires:
  13. './DropboxHandler': @DropboxHandler
  14. 'logger-sharelatex':
  15. log:->
  16. err:->
  17. @user_id = "23j21lk3j1312j321jkljkl"
  18. @req =
  19. session:
  20. user:
  21. _id: @user_id
  22. @res = {}
  23. describe "redirectUserToDropboxAuth", ->
  24. beforeEach ->
  25. @dropboxUrl = "www.dropbox.com"
  26. @DropboxHandler.getDropboxRegisterUrl.callsArgWith(1, null, @dropboxUrl)
  27. it "should call getDropboxRegisterUrl with the user id", (done)->
  28. @res.redirect = (redirectUrl)=>
  29. redirectUrl.should.equal @dropboxUrl
  30. @DropboxHandler.getDropboxRegisterUrl.calledWith(@user_id).should.equal true
  31. done()
  32. @controller.redirectUserToDropboxAuth @req, @res
  33. describe "completeDropboxRegistration", ->
  34. beforeEach ->
  35. @DropboxHandler.completeRegistration.callsArgWith(1)
  36. it "should call getDropboxRegisterUrl with the user id", (done)->
  37. @res.redirect = (redirectUrl)=>
  38. redirectUrl.should.equal "/user/settings#dropboxSettings"
  39. @DropboxHandler.completeRegistration.calledWith(@user_id).should.equal true
  40. done()
  41. @controller.completeDropboxRegistration @req, @res
  42. describe "unlinkDropbox", ->
  43. beforeEach ->
  44. @DropboxHandler.unlinkAccount.callsArgWith(1)
  45. it "should call getDropboxRegisterUrl with the user id", (done)->
  46. @res.redirect = (redirectUrl)=>
  47. redirectUrl.should.equal "/user/settings#dropboxSettings"
  48. @DropboxHandler.unlinkAccount.calledWith(@user_id).should.equal true
  49. done()
  50. @controller.unlinkDropbox @req, @res