RestoreManagerTests.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, { requires: {
  21. "logger-sharelatex": (this.logger = { log: sinon.stub(), error: sinon.stub() }),
  22. "./DocumentUpdaterManager": (this.DocumentUpdaterManager = {}),
  23. "./DiffManager": (this.DiffManager = {})
  24. }
  25. });
  26. this.callback = sinon.stub();
  27. this.project_id = "mock-project-id";
  28. this.doc_id = "mock-doc-id";
  29. this.user_id = "mock-user-id";
  30. return this.version = 42;
  31. });
  32. return describe("restoreToBeforeVersion", function() {
  33. beforeEach(function() {
  34. this.content = "mock content";
  35. this.DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4);
  36. this.DiffManager.getDocumentBeforeVersion = sinon.stub().callsArgWith(3, null, this.content);
  37. return this.RestoreManager.restoreToBeforeVersion(this.project_id, this.doc_id, this.version, this.user_id, this.callback);
  38. });
  39. it("should get the content before the requested version", function() {
  40. return this.DiffManager.getDocumentBeforeVersion
  41. .calledWith(this.project_id, this.doc_id, this.version)
  42. .should.equal(true);
  43. });
  44. it("should set the document in the document updater", function() {
  45. return this.DocumentUpdaterManager.setDocument
  46. .calledWith(this.project_id, this.doc_id, this.content, this.user_id)
  47. .should.equal(true);
  48. });
  49. return it("should call the callback", function() {
  50. return this.callback.called.should.equal(true);
  51. });
  52. });
  53. });