pushDocOpTests.coffee 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/RedisManager"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "RedisManager.getPreviousDocOpsTests", ->
  7. beforeEach ->
  8. @callback = sinon.stub()
  9. @RedisManager = SandboxedModule.require modulePath, requires:
  10. "redis" : createClient: () =>
  11. @rclient =
  12. auth: ->
  13. multi: => @rclient
  14. @doc_id = "doc-id-123"
  15. beforeEach ->
  16. @version = 70
  17. @op =
  18. { "mock": "op-1" }
  19. @jsonOp = JSON.stringify @op
  20. @rclient.rpush = sinon.stub().callsArgWith(2, null)
  21. @rclient.incr = sinon.stub().callsArgWith(1, null, @version.toString())
  22. @RedisManager.pushDocOp(@doc_id, @op, @callback)
  23. it "should push the op into redis", ->
  24. @rclient.rpush
  25. .calledWith("DocOps:#{@doc_id}", @jsonOp)
  26. .should.equal true
  27. it "should increment the version number", ->
  28. @rclient.incr
  29. .calledWith("DocVersion:#{@doc_id}")
  30. .should.equal true
  31. it "should call the callback with the new version", ->
  32. @callback.calledWith(null, @version).should.equal true