HttpControllerTests.coffee 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. "./DiffManager": @DiffManager = {}
  13. @doc_id = "doc-id-123"
  14. @project_id = "project-id-123"
  15. @version = 42
  16. @next = sinon.stub()
  17. describe "flushUpdatesWithLock", ->
  18. beforeEach ->
  19. @req =
  20. params:
  21. doc_id: @doc_id
  22. @res =
  23. send: sinon.stub()
  24. @HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
  25. @HttpController.flushUpdatesWithLock @req, @res, @next
  26. it "should process the updates", ->
  27. @HistoryManager.processUncompressedUpdatesWithLock
  28. .calledWith(@doc_id)
  29. .should.equal true
  30. it "should return a success code", ->
  31. @res.send.calledWith(204).should.equal true
  32. describe "getDiff", ->
  33. beforeEach ->
  34. @from = Date.now() - 10000
  35. @to = Date.now()
  36. @req =
  37. params:
  38. doc_id: @doc_id
  39. project_id: @project_id
  40. query:
  41. from: @from.toString()
  42. to: @to.toString()
  43. @res =
  44. send: sinon.stub()
  45. @diff = [ u: "mock-diff" ]
  46. @DiffManager.getDiff = sinon.stub().callsArgWith(4, null, @diff)
  47. @HttpController.getDiff @req, @res, @next
  48. it "should get the diff", ->
  49. @DiffManager.getDiff
  50. .calledWith(@project_id, @doc_id, parseInt(@from, 10), parseInt(@to, 10))
  51. .should.equal true
  52. it "should return the diff", ->
  53. @res.send.calledWith(JSON.stringify(diff: @diff)).should.equal true