ProjectApiControllerTests.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 modulePath = '../../../../app/src/Features/Project/ProjectApiController'
  14. const SandboxedModule = require('sandboxed-module')
  15. const sinon = require('sinon')
  16. describe('Project api controller', function () {
  17. beforeEach(function () {
  18. this.ProjectDetailsHandler = { getDetails: sinon.stub() }
  19. this.controller = SandboxedModule.require(modulePath, {
  20. requires: {
  21. './ProjectDetailsHandler': this.ProjectDetailsHandler,
  22. },
  23. })
  24. this.project_id = '321l3j1kjkjl'
  25. this.req = {
  26. params: {
  27. project_id: this.project_id,
  28. },
  29. session: {
  30. destroy: sinon.stub(),
  31. },
  32. }
  33. this.res = {}
  34. this.next = sinon.stub()
  35. return (this.projDetails = { name: 'something' })
  36. })
  37. describe('getProjectDetails', function () {
  38. it('should ask the project details handler for proj details', function (done) {
  39. this.ProjectDetailsHandler.getDetails.callsArgWith(
  40. 1,
  41. null,
  42. this.projDetails
  43. )
  44. this.res.json = data => {
  45. this.ProjectDetailsHandler.getDetails
  46. .calledWith(this.project_id)
  47. .should.equal(true)
  48. data.should.deep.equal(this.projDetails)
  49. return done()
  50. }
  51. return this.controller.getProjectDetails(this.req, this.res)
  52. })
  53. it('should send a 500 if there is an error', function () {
  54. this.ProjectDetailsHandler.getDetails.callsArgWith(1, 'error')
  55. this.controller.getProjectDetails(this.req, this.res, this.next)
  56. return this.next.calledWith('error').should.equal(true)
  57. })
  58. })
  59. })