RestoreManagerTests.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-disable
  2. no-return-assign,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const sinon = require('sinon')
  13. const chai = require('chai')
  14. const should = chai.should()
  15. const { expect } = chai
  16. const modulePath = '../../../../app/js/RestoreManager.js'
  17. const SandboxedModule = require('sandboxed-module')
  18. describe('RestoreManager', function () {
  19. beforeEach(function () {
  20. this.RestoreManager = SandboxedModule.require(modulePath, {
  21. requires: {
  22. 'logger-sharelatex': (this.logger = {
  23. log: sinon.stub(),
  24. error: sinon.stub()
  25. }),
  26. './DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
  27. './DiffManager': (this.DiffManager = {})
  28. }
  29. })
  30. this.callback = sinon.stub()
  31. this.project_id = 'mock-project-id'
  32. this.doc_id = 'mock-doc-id'
  33. this.user_id = 'mock-user-id'
  34. return (this.version = 42)
  35. })
  36. return describe('restoreToBeforeVersion', function () {
  37. beforeEach(function () {
  38. this.content = 'mock content'
  39. this.DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4)
  40. this.DiffManager.getDocumentBeforeVersion = sinon
  41. .stub()
  42. .callsArgWith(3, null, this.content)
  43. return this.RestoreManager.restoreToBeforeVersion(
  44. this.project_id,
  45. this.doc_id,
  46. this.version,
  47. this.user_id,
  48. this.callback
  49. )
  50. })
  51. it('should get the content before the requested version', function () {
  52. return this.DiffManager.getDocumentBeforeVersion
  53. .calledWith(this.project_id, this.doc_id, this.version)
  54. .should.equal(true)
  55. })
  56. it('should set the document in the document updater', function () {
  57. return this.DocumentUpdaterManager.setDocument
  58. .calledWith(this.project_id, this.doc_id, this.content, this.user_id)
  59. .should.equal(true)
  60. })
  61. return it('should call the callback', function () {
  62. return this.callback.called.should.equal(true)
  63. })
  64. })
  65. })