DocOpsManagerTests.coffee 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/DocOpsManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. {ObjectId} = require "mongojs"
  7. describe "DocOpsManager", ->
  8. beforeEach ->
  9. @doc_id = ObjectId().toString()
  10. @project_id = ObjectId().toString()
  11. @callback = sinon.stub()
  12. @DocOpsManager = SandboxedModule.require modulePath, requires:
  13. "./RedisManager": @RedisManager = {}
  14. "./TrackChangesManager": @TrackChangesManager = {}
  15. describe "getPreviousDocOps", ->
  16. beforeEach ->
  17. @ops = [ "mock-op-1", "mock-op-2" ]
  18. @start = 30
  19. @end = 32
  20. @RedisManager.getPreviousDocOps = sinon.stub().callsArgWith(3, null, @ops)
  21. @DocOpsManager.getPreviousDocOps @project_id, @doc_id, @start, @end, @callback
  22. it "should get the previous doc ops", ->
  23. @RedisManager.getPreviousDocOps
  24. .calledWith(@doc_id, @start, @end)
  25. .should.equal true
  26. it "should call the callback with the ops", ->
  27. @callback.calledWith(null, @ops).should.equal true
  28. describe "pushDocOp", ->
  29. beforeEach ->
  30. @op = "mock-op"
  31. @RedisManager.pushDocOp = sinon.stub().callsArgWith(2, null, @version = 42)
  32. @TrackChangesManager.pushUncompressedHistoryOp = sinon.stub().callsArg(3)
  33. @DocOpsManager.pushDocOp @project_id, @doc_id, @op, @callback
  34. it "should push the op in to the docOps list", ->
  35. @RedisManager.pushDocOp
  36. .calledWith(@doc_id, @op)
  37. .should.equal true
  38. it "should push the op into the pushUncompressedHistoryOp", ->
  39. @TrackChangesManager.pushUncompressedHistoryOp
  40. .calledWith(@project_id, @doc_id, @op)
  41. .should.equal true
  42. it "should call the callback with the version", ->
  43. @callback.calledWith(null, @version).should.equal true