RestoreManagerTests.coffee 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. expect = chai.expect
  5. modulePath = "../../../../app/js/RestoreManager.js"
  6. SandboxedModule = require('sandboxed-module')
  7. describe "RestoreManager", ->
  8. beforeEach ->
  9. @RestoreManager = SandboxedModule.require modulePath, requires:
  10. "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
  11. "./DocumentUpdaterManager": @DocumentUpdaterManager = {}
  12. "./DiffManager": @DiffManager = {}
  13. @callback = sinon.stub()
  14. @project_id = "mock-project-id"
  15. @doc_id = "mock-doc-id"
  16. @version = 42
  17. describe "restoreToBeforeVersion", ->
  18. beforeEach ->
  19. @content = "mock content"
  20. @DocumentUpdaterManager.setDocument = sinon.stub().callsArg(3)
  21. @DiffManager.getDocumentBeforeVersion = sinon.stub().callsArgWith(3, null, @content)
  22. @RestoreManager.restoreToBeforeVersion @project_id, @doc_id, @version, @callback
  23. it "should get the content before the requested version", ->
  24. @DiffManager.getDocumentBeforeVersion
  25. .calledWith(@project_id, @doc_id, @version)
  26. .should.equal true
  27. it "should set the document in the document updater", ->
  28. @DocumentUpdaterManager.setDocument
  29. .calledWith(@project_id, @doc_id, @content)
  30. .should.equal true
  31. it "should call the callback", ->
  32. @callback.called.should.equal true