GetOpsTests.coffee 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/ShareJsDB.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "ShareJsDB.getOps", ->
  7. beforeEach ->
  8. @doc_id = "document-id"
  9. @project_id = "project-id"
  10. @doc_key = "#{@project_id}:#{@doc_id}"
  11. @callback = sinon.stub()
  12. @ops = [{p: 20, t: "foo"}]
  13. @redis_ops = (JSON.stringify(op) for op in @ops)
  14. @ShareJsDB = SandboxedModule.require modulePath, requires:
  15. "./RedisManager": @RedisManager = {}
  16. "./DocOpsManager": @DocOpsManager = {}
  17. "./DocumentManager":{}
  18. "logger-sharelatex": {}
  19. describe "with start == end", ->
  20. beforeEach ->
  21. @start = @end = 42
  22. @ShareJsDB.getOps @doc_key, @start, @end, @callback
  23. it "should return an empty array", ->
  24. @callback.calledWith(null, []).should.equal true
  25. describe "with a non empty range", ->
  26. beforeEach ->
  27. @start = 35
  28. @end = 42
  29. @DocOpsManager.getPreviousDocOps = sinon.stub().callsArgWith(4, null, @ops)
  30. @ShareJsDB.getOps @doc_key, @start, @end, @callback
  31. it "should get the range from redis", ->
  32. @DocOpsManager.getPreviousDocOps
  33. .calledWith(@project_id, @doc_id, @start, @end-1)
  34. .should.equal true
  35. it "should return the ops", ->
  36. @callback.calledWith(null, @ops).should.equal true
  37. describe "with no specified end", ->
  38. beforeEach ->
  39. @start = 35
  40. @end = null
  41. @DocOpsManager.getPreviousDocOps = sinon.stub().callsArgWith(4, null, @ops)
  42. @ShareJsDB.getOps @doc_key, @start, @end, @callback
  43. it "should get until the end of the list", ->
  44. @DocOpsManager.getPreviousDocOps
  45. .calledWith(@project_id, @doc_id, @start, -1)
  46. .should.equal true