V1ProjectGetterTests.coffee 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. sinon = require('sinon')
  2. should = require('chai').should()
  3. SandboxedModule = require('sandboxed-module')
  4. modulePath = '../../../../app/js/Features/Project/V1ProjectGetter.js'
  5. describe 'V1ProjectGetter', ->
  6. beforeEach ->
  7. @fs =
  8. stat: sinon.stub()
  9. @path =
  10. resolve: sinon.stub().returns('path/to/integration/module')
  11. join: sinon.stub().returns('path/to/file/in/integration/module')
  12. @IntegrationProjectListGetter =
  13. findAllUsersProjects: sinon.stub()
  14. @V1ProjectGetter = SandboxedModule.require modulePath, requires:
  15. 'fs': @fs
  16. 'path': @path
  17. 'logger-sharelatex': log: ->
  18. 'path/to/file/in/integration/module': @IntegrationProjectListGetter
  19. @userId = 123
  20. @callback = sinon.stub()
  21. describe 'without overleaf-integration-web-module', ->
  22. beforeEach ->
  23. # Mock not finding integration module
  24. @fs.stat.yields({ code: 'mock-ENOENT-error' })
  25. # Call method
  26. @V1ProjectGetter.findAllUsersProjects @userId, @callback
  27. it 'should call the callback with no arguments', ->
  28. @callback.calledWith().should.equal true
  29. describe 'with overleaf-integration-web-module', ->
  30. beforeEach ->
  31. # Mock finding integration module
  32. @fs.stat.yields(null, isDirectory: sinon.stub().returns(true))
  33. # Mock integration module response
  34. @IntegrationProjectListGetter.findAllUsersProjects.yields(null, @response = {
  35. projects: [{ id: '123mockV1Id', title: 'mock title' }]
  36. tags: [{ name: 'mock tag', project_ids: ['123mockV1Id'] }]
  37. })
  38. # Call method
  39. @V1ProjectGetter.findAllUsersProjects @userId, @callback
  40. it 'should call the callback with all the projects and tags', ->
  41. @callback.calledWith(null, @response).should.equal true