ProjectApiControllerTests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const should = require('chai').should()
  14. const modulePath = '../../../../app/src/Features/Project/ProjectApiController'
  15. const SandboxedModule = require('sandboxed-module')
  16. const sinon = require('sinon')
  17. require('chai').should()
  18. describe('Project api controller', function() {
  19. beforeEach(function() {
  20. this.ProjectDetailsHandler = { getDetails: sinon.stub() }
  21. this.controller = SandboxedModule.require(modulePath, {
  22. globals: {
  23. console: console
  24. },
  25. requires: {
  26. './ProjectDetailsHandler': this.ProjectDetailsHandler,
  27. 'logger-sharelatex': {
  28. log() {}
  29. }
  30. }
  31. })
  32. this.project_id = '321l3j1kjkjl'
  33. this.req = {
  34. params: {
  35. project_id: this.project_id
  36. },
  37. session: {
  38. destroy: sinon.stub()
  39. }
  40. }
  41. this.res = {}
  42. this.next = sinon.stub()
  43. return (this.projDetails = { name: 'something' })
  44. })
  45. describe('getProjectDetails', function() {
  46. it('should ask the project details handler for proj details', function(done) {
  47. this.ProjectDetailsHandler.getDetails.callsArgWith(
  48. 1,
  49. null,
  50. this.projDetails
  51. )
  52. this.res.json = data => {
  53. this.ProjectDetailsHandler.getDetails
  54. .calledWith(this.project_id)
  55. .should.equal(true)
  56. data.should.deep.equal(this.projDetails)
  57. return done()
  58. }
  59. return this.controller.getProjectDetails(this.req, this.res)
  60. })
  61. it('should send a 500 if there is an error', function() {
  62. this.ProjectDetailsHandler.getDetails.callsArgWith(1, 'error')
  63. this.controller.getProjectDetails(this.req, this.res, this.next)
  64. return this.next.calledWith('error').should.equal(true)
  65. })
  66. })
  67. })