GetOpsTests.coffee 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. describe "with start == end", ->
  19. beforeEach ->
  20. @start = @end = 42
  21. @ShareJsDB.getOps @doc_key, @start, @end, @callback
  22. it "should return an empty array", ->
  23. @callback.calledWith(null, []).should.equal true
  24. describe "with a non empty range", ->
  25. beforeEach ->
  26. @start = 35
  27. @end = 42
  28. @DocOpsManager.getPreviousDocOps = sinon.stub().callsArgWith(4, null, @ops)
  29. @ShareJsDB.getOps @doc_key, @start, @end, @callback
  30. it "should get the range from redis", ->
  31. @DocOpsManager.getPreviousDocOps
  32. .calledWith(@project_id, @doc_id, @start, @end-1)
  33. .should.equal true
  34. it "should return the ops", ->
  35. @callback.calledWith(null, @ops).should.equal true
  36. describe "with no specified end", ->
  37. beforeEach ->
  38. @start = 35
  39. @end = null
  40. @DocOpsManager.getPreviousDocOps = sinon.stub().callsArgWith(4, null, @ops)
  41. @ShareJsDB.getOps @doc_key, @start, @end, @callback
  42. it "should get until the end of the list", ->
  43. @DocOpsManager.getPreviousDocOps
  44. .calledWith(@project_id, @doc_id, @start, -1)
  45. .should.equal true