TemplatesControllerTests.js 3.3 KB

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