RestoreManagerTests.coffee 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. @user_id = "mock-user-id"
  17. @version = 42
  18. describe "restoreToBeforeVersion", ->
  19. beforeEach ->
  20. @content = "mock content"
  21. @DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4)
  22. @DiffManager.getDocumentBeforeVersion = sinon.stub().callsArgWith(3, null, @content)
  23. @RestoreManager.restoreToBeforeVersion @project_id, @doc_id, @version, @user_id, @callback
  24. it "should get the content before the requested version", ->
  25. @DiffManager.getDocumentBeforeVersion
  26. .calledWith(@project_id, @doc_id, @version)
  27. .should.equal true
  28. it "should set the document in the document updater", ->
  29. @DocumentUpdaterManager.setDocument
  30. .calledWith(@project_id, @doc_id, @content, @user_id)
  31. .should.equal true
  32. it "should call the callback", ->
  33. @callback.called.should.equal true