GettingDoc.coffee 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.getDoc', ->
  7. beforeEach ->
  8. @rclient = {}
  9. @rclient.auth = () ->
  10. @rclient.multi = () => @rclient
  11. @RedisManager = SandboxedModule.require modulePath, requires:
  12. "redis-sharelatex": @redis =
  13. createClient: () => @rclient
  14. @doc_id = "doc-id-123"
  15. @lines = ["one", "two", "three"]
  16. @jsonlines = JSON.stringify @lines
  17. @version = 42
  18. @callback = sinon.stub()
  19. @rclient.get = sinon.stub()
  20. @rclient.exec = sinon.stub().callsArgWith(0, null, [@jsonlines, @version])
  21. @RedisManager.getDoc @doc_id, @callback
  22. it "should get the lines from redis", ->
  23. @rclient.get
  24. .calledWith("doclines:#{@doc_id}")
  25. .should.equal true
  26. it "should get the version from", ->
  27. @rclient.get
  28. .calledWith("DocVersion:#{@doc_id}")
  29. .should.equal true
  30. it 'should return the document', ->
  31. @callback
  32. .calledWith(null, @lines, @version)
  33. .should.equal true