TemplatesControllerTests.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 SandboxedModule = require('sandboxed-module')
  14. const assert = require('assert')
  15. const { expect } = require('chai')
  16. const sinon = require('sinon')
  17. const ProjectHelper = require('../../../../app/src/Features/Project/ProjectHelper')
  18. const modulePath = '../../../../app/src/Features/Templates/TemplatesController'
  19. describe('TemplatesController', function () {
  20. beforeEach(function () {
  21. this.user_id = 'user-id'
  22. this.TemplatesController = SandboxedModule.require(modulePath, {
  23. requires: {
  24. '../Project/ProjectHelper': ProjectHelper,
  25. '../Authentication/AuthenticationController':
  26. (this.AuthenticationController = {
  27. getLoggedInUserId: sinon.stub().returns(this.user_id),
  28. }),
  29. './TemplatesManager': (this.TemplatesManager = {
  30. createProjectFromV1Template: sinon.stub(),
  31. }),
  32. },
  33. })
  34. this.next = sinon.stub()
  35. this.req = {
  36. body: {
  37. brandVariationId: 'brand-variation-id',
  38. compiler: 'compiler',
  39. mainFile: 'main-file',
  40. templateId: 'template-id',
  41. templateName: 'template-name',
  42. templateVersionId: 'template-version-id',
  43. },
  44. session: {
  45. templateData: 'template-data',
  46. user: {
  47. _id: this.user_id,
  48. },
  49. },
  50. }
  51. return (this.res = { redirect: sinon.stub() })
  52. })
  53. describe('createProjectFromV1Template', function () {
  54. describe('on success', function () {
  55. beforeEach(function () {
  56. this.project = { _id: 'project-id' }
  57. this.TemplatesManager.createProjectFromV1Template.yields(
  58. null,
  59. this.project
  60. )
  61. return this.TemplatesController.createProjectFromV1Template(
  62. this.req,
  63. this.res,
  64. this.next
  65. )
  66. })
  67. it('should call TemplatesManager', function () {
  68. return this.TemplatesManager.createProjectFromV1Template.should.have.been.calledWithMatch(
  69. 'brand-variation-id',
  70. 'compiler',
  71. 'main-file',
  72. 'template-id',
  73. 'template-name',
  74. 'template-version-id',
  75. 'user-id'
  76. )
  77. })
  78. it('should redirect to project', function () {
  79. return this.res.redirect.should.have.been.calledWith(
  80. '/project/project-id'
  81. )
  82. })
  83. it('should delete session', function () {
  84. return expect(this.req.session.templateData).to.be.undefined
  85. })
  86. })
  87. describe('on error', function () {
  88. beforeEach(function () {
  89. this.TemplatesManager.createProjectFromV1Template.yields('error')
  90. return this.TemplatesController.createProjectFromV1Template(
  91. this.req,
  92. this.res,
  93. this.next
  94. )
  95. })
  96. it('should call next with error', function () {
  97. return this.next.should.have.been.calledWith('error')
  98. })
  99. it('should not redirect', function () {
  100. return this.res.redirect.called.should.equal(false)
  101. })
  102. })
  103. })
  104. })