GetNumberOfDocsInMemoryTests.coffee 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. path = require("path")
  2. sinon = require("sinon")
  3. SandboxedModule = require('sandboxed-module')
  4. modulePath = path.join __dirname, '../../../../app/js/Features/DocumentUpdater/DocumentUpdaterHandler'
  5. describe "getNumberOfDocsInMemory", ->
  6. beforeEach ->
  7. @host = "doc.updater"
  8. @noOfDocs = 42
  9. @callback = sinon.stub()
  10. @DocumentUpdateHandler = SandboxedModule.require modulePath, requires:
  11. "redis-sharelatex" :
  12. createClient: () ->
  13. auth:->
  14. "soa-req-id": null
  15. "logger-sharelatex": @logger =
  16. log: sinon.stub()
  17. error: sinon.stub()
  18. "../../infrastructure/Metrics" : @metrics
  19. "../../Features/Project/ProjectLocator": @ProjectLocator = {}
  20. "../../models/Project":Project:{}
  21. "request" : defaults: () => @request = {}
  22. "settings-sharelatex":
  23. apis: documentupdater: url: @host
  24. redis: web:{}
  25. @request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, JSON.stringify(total: @noOfDocs))
  26. @DocumentUpdateHandler.getNumberOfDocsInMemory @callback
  27. it "should call the doc updater", ->
  28. @request.get
  29. .calledWith("#{@host}/total")
  30. .should.equal true
  31. it "should return the number of docs", ->
  32. @callback
  33. .calledWith(null, @noOfDocs)
  34. .should.equal true