RedisManagerTests.coffee 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. expect = chai.expect
  5. modulePath = "../../../../app/js/RedisManager.js"
  6. SandboxedModule = require('sandboxed-module')
  7. describe "RedisManager", ->
  8. beforeEach ->
  9. @RedisManager = SandboxedModule.require modulePath, requires:
  10. "redis" :
  11. createClient: () => @rclient =
  12. auth: sinon.stub()
  13. "settings-sharelatex": {}
  14. @doc_id = "doc-id-123"
  15. @batchSize = 100
  16. @callback = sinon.stub()
  17. describe "getOldestRawUpdates", ->
  18. beforeEach ->
  19. @rawUpdates = [ {v: 42, op: "mock-op-42"}, { v: 45, op: "mock-op-45" }]
  20. @jsonUpdates = (JSON.stringify(update) for update in @rawUpdates)
  21. @rclient.lrange = sinon.stub().callsArgWith(3, null, @jsonUpdates)
  22. @RedisManager.getOldestRawUpdates @doc_id, @batchSize, @callback
  23. it "should read the updates from redis", ->
  24. @rclient.lrange
  25. .calledWith("UncompressedHistoryOps:#{@doc_id}", 0, @batchSize - 1)
  26. .should.equal true
  27. it "should call the callback with the parsed ops", ->
  28. @callback.calledWith(null, @rawUpdates).should.equal true
  29. describe "deleteOldestRawUpdates", ->
  30. beforeEach ->
  31. @rclient.ltrim = sinon.stub().callsArg(3)
  32. @RedisManager.deleteOldestRawUpdates @doc_id, @batchSize, @callback
  33. it "should delete the updates from redis", ->
  34. @rclient.ltrim
  35. .calledWith("UncompressedHistoryOps:#{@doc_id}", @batchSize, -1)
  36. .should.equal true
  37. it "should call the callback", ->
  38. @callback.called.should.equal true