TemplatesControllerTests.js 3.3 KB

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