getDocTests.coffee 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/PersistenceManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. {ObjectId} = require("mongojs")
  7. describe "PersistenceManager.getDoc", ->
  8. beforeEach ->
  9. @PersistenceManager = SandboxedModule.require modulePath, requires:
  10. "request": @request = sinon.stub()
  11. "settings-sharelatex": @Settings = {}
  12. "./Metrics": @Metrics =
  13. Timer: class Timer
  14. done: sinon.stub()
  15. "logger-sharelatex": @logger = {warn: sinon.stub()}
  16. "./mongojs":
  17. db: @db = { docOps: {} }
  18. ObjectId: ObjectId
  19. @project_id = ObjectId().toString()
  20. @doc_id = ObjectId().toString()
  21. @callback = sinon.stub()
  22. @lines = ["mock", "doc", "lines"]
  23. @version = 42
  24. describe "successfully", ->
  25. beforeEach ->
  26. @PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines)
  27. @PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version)
  28. @PersistenceManager.getDoc @project_id, @doc_id, @callback
  29. it "should look up the doc in the web api", ->
  30. @PersistenceManager.getDocFromWeb
  31. .calledWith(@project_id, @doc_id)
  32. .should.equal true
  33. it "should look up the version in Mongo", ->
  34. @PersistenceManager.getDocVersionInMongo
  35. .calledWith(@doc_id)
  36. .should.equal true
  37. it "should call the callback with the lines and version", ->
  38. @callback.calledWith(null, @lines, @version).should.equal true