pushDocOpTests.coffee 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/RedisManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "RedisManager.pushDocOp", ->
  7. beforeEach ->
  8. @RedisManager = SandboxedModule.require modulePath, requires:
  9. "./ZipManager": {}
  10. "redis-sharelatex": createClient: () =>
  11. @rclient ?=
  12. auth: () ->
  13. multi: () => @rclient
  14. "logger-sharelatex": @logger = {log: sinon.stub()}
  15. @doc_id = "doc-id-123"
  16. @callback = sinon.stub()
  17. @rclient.rpush = sinon.stub()
  18. @rclient.expire = sinon.stub()
  19. @rclient.incr = sinon.stub()
  20. @rclient.ltrim = sinon.stub()
  21. describe "successfully", ->
  22. beforeEach ->
  23. @op = { op: [{ i: "foo", p: 4 }] }
  24. @version = 42
  25. _ = null
  26. @rclient.exec = sinon.stub().callsArgWith(0, null, [_, _, _, @version])
  27. @RedisManager.pushDocOp @doc_id, @op, @callback
  28. it "should push the doc op into the doc ops list", ->
  29. @rclient.rpush
  30. .calledWith("DocOps:#{@doc_id}", JSON.stringify(@op))
  31. .should.equal true
  32. it "should renew the expiry ttl on the doc ops array", ->
  33. @rclient.expire
  34. .calledWith("DocOps:#{@doc_id}", @RedisManager.DOC_OPS_TTL)
  35. .should.equal true
  36. it "should truncate the list to 100 members", ->
  37. @rclient.ltrim
  38. .calledWith("DocOps:#{@doc_id}", -@RedisManager.DOC_OPS_MAX_LENGTH, -1)
  39. .should.equal true
  40. it "should increment the version number", ->
  41. @rclient.incr
  42. .calledWith("DocVersion:#{@doc_id}")
  43. .should.equal true
  44. it "should call the callback with the version number", ->
  45. @callback.calledWith(null, parseInt(@version, 10)).should.equal true