flushAndDeleteDocTests.coffee 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. "./TrackChangesManager": @TrackChangesManager = {}
  12. "logger-sharelatex": @logger = {log: sinon.stub()}
  13. "./DocOpsManager" :{}
  14. "./Metrics": @Metrics =
  15. Timer: class Timer
  16. done: sinon.stub()
  17. @project_id = "project-id-123"
  18. @doc_id = "doc-id-123"
  19. @callback = sinon.stub()
  20. describe "successfully", ->
  21. beforeEach ->
  22. @RedisManager.removeDocFromMemory = sinon.stub().callsArg(2)
  23. @DocumentManager.flushDocIfLoaded = sinon.stub().callsArgWith(2)
  24. @TrackChangesManager.flushDocChanges = sinon.stub().callsArg(2)
  25. @DocumentManager.flushAndDeleteDoc @project_id, @doc_id, @callback
  26. it "should flush the doc", ->
  27. @DocumentManager.flushDocIfLoaded
  28. .calledWith(@project_id, @doc_id)
  29. .should.equal true
  30. it "should remove the doc from redis", ->
  31. @RedisManager.removeDocFromMemory
  32. .calledWith(@project_id, @doc_id)
  33. .should.equal true
  34. it "should call the callback without error", ->
  35. @callback.calledWith(null).should.equal true
  36. it "should time the execution", ->
  37. @Metrics.Timer::done.called.should.equal true
  38. it "should flush to track changes", ->
  39. @TrackChangesManager.flushDocChanges
  40. .calledWith(@project_id, @doc_id)
  41. .should.equal true