InactiveProjectManagerTests.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* eslint-disable
  2. node/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 SandboxedModule = require('sandboxed-module')
  15. const assert = require('assert')
  16. const path = require('path')
  17. const sinon = require('sinon')
  18. const modulePath = path.join(
  19. __dirname,
  20. '../../../../app/src/Features/InactiveData/InactiveProjectManager'
  21. )
  22. const { expect } = require('chai')
  23. const { ObjectId } = require('mongodb')
  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.InactiveProjectManager = SandboxedModule.require(modulePath, {
  37. requires: {
  38. mongodb: { ObjectId },
  39. '@overleaf/settings': this.settings,
  40. '../Docstore/DocstoreManager': this.DocstoreManager,
  41. '../Project/ProjectUpdateHandler': this.ProjectUpdateHandler,
  42. '../Project/ProjectGetter': this.ProjectGetter,
  43. '../../models/Project': {},
  44. },
  45. })
  46. return (this.project_id = '1234')
  47. })
  48. describe('reactivateProjectIfRequired', function () {
  49. beforeEach(function () {
  50. this.project = { active: false }
  51. this.ProjectGetter.getProject.callsArgWith(2, null, this.project)
  52. return this.ProjectUpdateHandler.markAsActive.callsArgWith(1)
  53. })
  54. it('should call unarchiveProject', function (done) {
  55. this.DocstoreManager.unarchiveProject.callsArgWith(1)
  56. return this.InactiveProjectManager.reactivateProjectIfRequired(
  57. this.project_id,
  58. err => {
  59. this.DocstoreManager.unarchiveProject
  60. .calledWith(this.project_id)
  61. .should.equal(true)
  62. this.ProjectUpdateHandler.markAsActive
  63. .calledWith(this.project_id)
  64. .should.equal(true)
  65. return done()
  66. }
  67. )
  68. })
  69. it('should not mark project as active if error with unarchiving', function (done) {
  70. const error = new Error('error')
  71. this.DocstoreManager.unarchiveProject.callsArgWith(1, error)
  72. return this.InactiveProjectManager.reactivateProjectIfRequired(
  73. this.project_id,
  74. err => {
  75. err.should.equal(error)
  76. this.DocstoreManager.unarchiveProject
  77. .calledWith(this.project_id)
  78. .should.equal(true)
  79. this.ProjectUpdateHandler.markAsActive
  80. .calledWith(this.project_id)
  81. .should.equal(false)
  82. return done()
  83. }
  84. )
  85. })
  86. it('should not call unarchiveProject if it is active', function (done) {
  87. this.project.active = true
  88. this.DocstoreManager.unarchiveProject.callsArgWith(1)
  89. return this.InactiveProjectManager.reactivateProjectIfRequired(
  90. this.project_id,
  91. err => {
  92. this.DocstoreManager.unarchiveProject
  93. .calledWith(this.project_id)
  94. .should.equal(false)
  95. this.ProjectUpdateHandler.markAsActive
  96. .calledWith(this.project_id)
  97. .should.equal(false)
  98. return done()
  99. }
  100. )
  101. })
  102. })
  103. describe('deactivateProject', function () {
  104. it('should call unarchiveProject and markAsInactive', function (done) {
  105. this.DocstoreManager.archiveProject.callsArgWith(1)
  106. this.ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  107. return this.InactiveProjectManager.deactivateProject(
  108. this.project_id,
  109. err => {
  110. this.DocstoreManager.archiveProject
  111. .calledWith(this.project_id)
  112. .should.equal(true)
  113. this.ProjectUpdateHandler.markAsInactive
  114. .calledWith(this.project_id)
  115. .should.equal(true)
  116. return done()
  117. }
  118. )
  119. })
  120. it('should not call markAsInactive if there was a problem archiving in docstore', function (done) {
  121. this.DocstoreManager.archiveProject.callsArgWith(1, 'errorrr')
  122. this.ProjectUpdateHandler.markAsInactive.callsArgWith(1)
  123. return this.InactiveProjectManager.deactivateProject(
  124. this.project_id,
  125. err => {
  126. err.should.equal('errorrr')
  127. this.DocstoreManager.archiveProject
  128. .calledWith(this.project_id)
  129. .should.equal(true)
  130. this.ProjectUpdateHandler.markAsInactive
  131. .calledWith(this.project_id)
  132. .should.equal(false)
  133. return done()
  134. }
  135. )
  136. })
  137. })
  138. })