ProjectApiControllerTests.mjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS102: Remove unnecessary code created because of implicit returns
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  7. */
  8. import esmock from 'esmock'
  9. import sinon from 'sinon'
  10. const modulePath = '../../../../app/src/Features/Project/ProjectApiController'
  11. describe('Project api controller', function () {
  12. beforeEach(async function () {
  13. this.ProjectDetailsHandler = { getDetails: sinon.stub() }
  14. this.controller = await esmock.strict(modulePath, {
  15. '../../../../app/src/Features/Project/ProjectDetailsHandler':
  16. this.ProjectDetailsHandler,
  17. })
  18. this.project_id = '321l3j1kjkjl'
  19. this.req = {
  20. params: {
  21. project_id: this.project_id,
  22. },
  23. session: {
  24. destroy: sinon.stub(),
  25. },
  26. }
  27. this.res = {}
  28. this.next = sinon.stub()
  29. return (this.projDetails = { name: 'something' })
  30. })
  31. describe('getProjectDetails', function () {
  32. it('should ask the project details handler for proj details', function (done) {
  33. this.ProjectDetailsHandler.getDetails.callsArgWith(
  34. 1,
  35. null,
  36. this.projDetails
  37. )
  38. this.res.json = data => {
  39. this.ProjectDetailsHandler.getDetails
  40. .calledWith(this.project_id)
  41. .should.equal(true)
  42. data.should.deep.equal(this.projDetails)
  43. return done()
  44. }
  45. return this.controller.getProjectDetails(this.req, this.res)
  46. })
  47. it('should send a 500 if there is an error', function () {
  48. this.ProjectDetailsHandler.getDetails.callsArgWith(1, 'error')
  49. this.controller.getProjectDetails(this.req, this.res, this.next)
  50. return this.next.calledWith('error').should.equal(true)
  51. })
  52. })
  53. })