prependDocOpsTests.coffee 860 B

1234567891011121314151617181920212223242526272829303132
  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.clearDocFromPendingUpdatesSet", ->
  7. beforeEach ->
  8. @doc_id = "document-id"
  9. @callback = sinon.stub()
  10. @RedisManager = SandboxedModule.require modulePath, requires:
  11. "redis" : createClient: () =>
  12. @rclient = auth:->
  13. @rclient.lpush = sinon.stub().callsArg(2)
  14. @ops = [
  15. { "mock" : "op-1" },
  16. { "mock" : "op-2" }
  17. ]
  18. @reversedJsonOps = @ops.map((op) -> JSON.stringify op).reverse()
  19. @RedisManager.prependDocOps(@doc_id, @ops, @callback)
  20. it "should push the reversed JSONed ops", ->
  21. @rclient.lpush
  22. .calledWith("DocOps:#{@doc_id}", @reversedJsonOps)
  23. .should.equal true
  24. it "should return the callback", ->
  25. @callback.called.should.equal true