V1ProjectGetterTests.coffee 2.0 KB

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