setDocTests.coffee 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/PersistenceManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "PersistenceManager.setDoc", ->
  7. beforeEach ->
  8. @PersistenceManager = SandboxedModule.require modulePath, requires:
  9. "request": @request = sinon.stub()
  10. "settings-sharelatex": @Settings = {}
  11. "./Metrics": @Metrics =
  12. Timer: class Timer
  13. done: sinon.stub()
  14. "logger-sharelatex": @logger = {warn: sinon.stub()}
  15. @project_id = "mock-project-id"
  16. @doc_id = "mock-doc-id"
  17. @callback = sinon.stub()
  18. @lines = ["mock", "doc", "lines"]
  19. @PersistenceManager.setDocInWeb = sinon.stub().callsArg(3)
  20. @PersistenceManager.setDocVersionInMongo = sinon.stub().callsArg(2)
  21. @PersistenceManager.setDoc @project_id, @doc_id, @lines, @version, @callback
  22. it "should set the doc in the web api", ->
  23. @PersistenceManager.setDocInWeb
  24. .calledWith(@project_id, @doc_id, @lines)
  25. .should.equal true
  26. it "should set the doc version in mongo", ->
  27. @PersistenceManager.setDocVersionInMongo
  28. .calledWith(@doc_id, @version)
  29. .should.equal true
  30. it "should call the callback", ->
  31. @callback.called.should.equal true