InactiveProjectManagerTests.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* eslint-disable
  2. handle-callback-err,
  3. max-len,
  4. no-return-assign,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const should = require('chai').should()
  15. const SandboxedModule = require('sandboxed-module')
  16. const assert = require('assert')
  17. const path = require('path')
  18. const sinon = require('sinon')
  19. const modulePath = path.join(
  20. __dirname,
  21. '../../../../app/src/Features/InactiveData/InactiveProjectManager'
  22. )
  23. const { expect } = require('chai')
  24. describe('InactiveProjectManager', function() {
  25. beforeEach(function() {
  26. this.settings = {}
  27. this.DocstoreManager = {
  28. unarchiveProject: sinon.stub(),
  29. archiveProject: sinon.stub()
  30. }
  31. this.ProjectUpdateHandler = {
  32. markAsActive: sinon.stub(),
  33. markAsInactive: sinon.stub()
  34. }
  35. this.ProjectGetter = { getProject: sinon.stub() }
  36. this.TrackChangesManager = { archiveProject: sinon.stub() }
  37. this.InactiveProjectManager = SandboxedModule.require(modulePath, {
  38. globals: {
  39. console: console
  40. },
  41. requires: {
  42. 'settings-sharelatex': this.settings,
  43. 'logger-sharelatex': {
  44. log() {},
  45. warn() {},
  46. err() {}
  47. },
  48. '../Docstore/DocstoreManager': this.DocstoreManager,
  49. '../Project/ProjectUpdateHandler': this.ProjectUpdateHandler,
  50. '../Project/ProjectGetter': this.ProjectGetter,
  51. '../TrackChanges/TrackChangesManager': this.TrackChangesManager,
  52. '../../models/Project': {}
  53. }
  54. })
  55. return (this.project_id = '1234')
  56. })
  57. describe('reactivateProjectIfRequired', function() {
  58. beforeEach(function() {
  59. this.project = { active: false }
  60. this.ProjectGetter.getProject.callsArgWith(2, null, this.project)
  61. return this.ProjectUpdateHandler.markAsActive.callsArgWith(1)
  62. })
  63. it('should call unarchiveProject', function(done) {
  64. this.DocstoreManager.unarchiveProject.callsArgWith(1)
  65. return this.InactiveProjectManager.reactivateProjectIfRequired(
  66. this.project_id,
  67. err => {
  68. this.DocstoreManager.unarchiveProject
  69. .calledWith(this.project_id)
  70. .should.equal(true)
  71. this.ProjectUpdateHandler.markAsActive
  72. .calledWith(this.project_id)
  73. .should.equal(true)
  74. return done()
  75. }
  76. )
  77. })
  78. it('should not mark project as active if error with unarchiving', function(done) {
  79. const error = new Error('error')
  80. this.DocstoreManager.unarchiveProject.callsArgWith(1, error)
  81. return this.InactiveProjectManager.reactivateProjectIfRequired(
  82. this.project_id,
  83. err => {
  84. err.should.equal(error)
  85. this.DocstoreManager.unarchiveProject
  86. .calledWith(this.project_id)
  87. .should.equal(true)
  88. this.ProjectUpdateHandler.markAsActive
  89. .calledWith(this.project_id)
  90. .should.equal(false)
  91. return done()
  92. }
  93. )
  94. })
  95. it('should not call unarchiveProject if it is active', function(done) {
  96. this.project.active = true
  97. this.DocstoreManager.unarchiveProject.callsArgWith(1)
  98. return this.InactiveProjectManager.reactivateProjectIfRequired(
  99. this.project_id,
  100. err => {
  101. this.DocstoreManager.unarchiveProject
  102. .calledWith(this.project_id)
  103. .should.equal(false)
  104. this.ProjectUpdateHandler.markAsActive
  105. .calledWith(this.project_id)
  106. .should.equal(false)
  107. return done()
  108. }
  109. )
  110. })
  111. })
  112. describe('deactivateProject', function() {
  113. it('should call unarchiveProject and markAsInactive', function(done) {
  114. this.DocstoreManager.archiveProject.callsArgWith(1)
  115. this.TrackChangesManager.archiveProject.callsArgWith(1)
  116. this.ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  117. return this.InactiveProjectManager.deactivateProject(
  118. this.project_id,
  119. err => {
  120. this.DocstoreManager.archiveProject
  121. .calledWith(this.project_id)
  122. .should.equal(true)
  123. // @TrackChangesManager.archiveProject.calledWith(@project_id).should.equal true
  124. this.ProjectUpdateHandler.markAsInactive
  125. .calledWith(this.project_id)
  126. .should.equal(true)
  127. return done()
  128. }
  129. )
  130. })
  131. it('should not call markAsInactive if there was a problem archiving in docstore', function(done) {
  132. this.DocstoreManager.archiveProject.callsArgWith(1, 'errorrr')
  133. this.TrackChangesManager.archiveProject.callsArgWith(1)
  134. this.ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  135. return this.InactiveProjectManager.deactivateProject(
  136. this.project_id,
  137. err => {
  138. err.should.equal('errorrr')
  139. this.DocstoreManager.archiveProject
  140. .calledWith(this.project_id)
  141. .should.equal(true)
  142. this.ProjectUpdateHandler.markAsInactive
  143. .calledWith(this.project_id)
  144. .should.equal(false)
  145. return done()
  146. }
  147. )
  148. })
  149. })
  150. })