flushAndDeleteDocTests.coffee 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/DocumentManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "DocumentUpdater - flushAndDeleteDoc", ->
  7. beforeEach ->
  8. @DocumentManager = SandboxedModule.require modulePath, requires:
  9. "./RedisManager": @RedisManager = {}
  10. "./PersistenceManager": @PersistenceManager = {}
  11. "logger-sharelatex": @logger = {log: sinon.stub()}
  12. "./DocOpsManager" :{}
  13. "./Metrics": @Metrics =
  14. Timer: class Timer
  15. done: sinon.stub()
  16. @project_id = "project-id-123"
  17. @doc_id = "doc-id-123"
  18. @callback = sinon.stub()
  19. describe "successfully", ->
  20. beforeEach ->
  21. @RedisManager.removeDocFromMemory = sinon.stub().callsArg(2)
  22. @DocumentManager.flushDocIfLoaded = sinon.stub().callsArgWith(2)
  23. @DocumentManager.flushAndDeleteDoc @project_id, @doc_id, @callback
  24. it "should flush the doc", ->
  25. @DocumentManager.flushDocIfLoaded
  26. .calledWith(@project_id, @doc_id)
  27. .should.equal true
  28. it "should remove the doc from redis", ->
  29. @RedisManager.removeDocFromMemory
  30. .calledWith(@project_id, @doc_id)
  31. .should.equal true
  32. it "should call the callback without error", ->
  33. @callback.calledWith(null).should.equal true
  34. it "should time the execution", ->
  35. @Metrics.Timer::done.called.should.equal true