DropboxProjectControllerTests.coffee 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/DropboxProjectController.js'
  6. describe 'DropboxProjectController', ->
  7. beforeEach ->
  8. @DropboxProjectController = SandboxedModule.require modulePath, requires:
  9. './DropboxHandler': @DropboxHandler = {}
  10. '../Project/ProjectGetter': @ProjectGetter = {}
  11. 'logger-sharelatex':
  12. log:->
  13. err:->
  14. @project_id = "project-id-123"
  15. @user_id = "user-id-123"
  16. @req = {}
  17. @res =
  18. json: sinon.stub()
  19. describe "getStatus", ->
  20. beforeEach ->
  21. @req.params =
  22. Project_id: @project_id
  23. @ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, { owner_ref: @user_id })
  24. @DropboxHandler.getUserRegistrationStatus = sinon.stub().callsArgWith(1, null, @status = {"mock": "status"})
  25. @DropboxProjectController.getStatus @req, @res
  26. it "should look up the project owner", ->
  27. @ProjectGetter.getProject
  28. .calledWith(@project_id, {owner_ref: 1})
  29. .should.equal true
  30. it "should get the owner's Dropbox status", ->
  31. @DropboxHandler.getUserRegistrationStatus
  32. .calledWith(@user_id)
  33. .should.equal true
  34. it "should send the status to the client", ->
  35. @res.json.calledWith(@status).should.equal true