deleteProjectTests.coffee 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/HttpController.js"
  5. SandboxedModule = require('sandboxed-module')
  6. Errors = require "../../../../app/js/Errors.js"
  7. describe "HttpController - deleteProject", ->
  8. beforeEach ->
  9. @HttpController = SandboxedModule.require modulePath, requires:
  10. "./DocumentManager": @DocumentManager = {}
  11. "./ProjectManager": @ProjectManager = {}
  12. "logger-sharelatex" : @logger = { log: sinon.stub() }
  13. "./Metrics": @Metrics = {}
  14. @Metrics.Timer = class Timer
  15. done: sinon.stub()
  16. @project_id = "project-id-123"
  17. @res =
  18. send: sinon.stub()
  19. @req =
  20. params:
  21. project_id: @project_id
  22. @next = sinon.stub()
  23. describe "successfully", ->
  24. beforeEach ->
  25. @ProjectManager.flushAndDeleteProjectWithLocks = sinon.stub().callsArgWith(1)
  26. @HttpController.deleteProject(@req, @res, @next)
  27. it "should delete the project", ->
  28. @ProjectManager.flushAndDeleteProjectWithLocks
  29. .calledWith(@project_id)
  30. .should.equal true
  31. it "should return a successful No Content response", ->
  32. @res.send
  33. .calledWith(204)
  34. .should.equal true
  35. it "should log the request", ->
  36. @logger.log
  37. .calledWith(project_id: @project_id, "deleting project via http")
  38. .should.equal true
  39. it "should time the request", ->
  40. @Metrics.Timer::done.called.should.equal true
  41. describe "when an errors occurs", ->
  42. beforeEach ->
  43. @ProjectManager.flushAndDeleteProjectWithLocks = sinon.stub().callsArgWith(1, new Error("oops"))
  44. @HttpController.deleteProject(@req, @res, @next)
  45. it "should call next with the error", ->
  46. @next
  47. .calledWith(new Error("oops"))
  48. .should.equal true