HttpControllerTests.coffee 998 B

123456789101112131415161718192021222324252627282930313233343536
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. expect = chai.expect
  5. modulePath = "../../../../app/js/HttpController.js"
  6. SandboxedModule = require('sandboxed-module')
  7. describe "HttpController", ->
  8. beforeEach ->
  9. @HttpController = SandboxedModule.require modulePath, requires:
  10. "logger-sharelatex": { log: sinon.stub() }
  11. "./HistoryManager": @HistoryManager = {}
  12. @doc_id = "doc-id-123"
  13. @version = 42
  14. @next = sinon.stub()
  15. describe "appendUpdates", ->
  16. beforeEach ->
  17. @req =
  18. params:
  19. doc_id: @doc_id
  20. body:
  21. docOps: @docOps = ["mock-ops"]
  22. version: @version
  23. @res =
  24. send: sinon.stub()
  25. @HistoryManager.compressAndSaveRawUpdates = sinon.stub().callsArg(2)
  26. @HttpController.appendUpdates @req, @res, @next
  27. it "should append the updates", ->
  28. @HistoryManager.compressAndSaveRawUpdates
  29. .calledWith(@doc_id, @docOps)
  30. .should.equal true
  31. it "should return a success code", ->
  32. @res.send.calledWith(204).should.equal true