updateProjectTests.coffee 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/ProjectManager.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "ProjectManager", ->
  7. beforeEach ->
  8. @ProjectManager = SandboxedModule.require modulePath, requires:
  9. "./RedisManager": @RedisManager = {}
  10. "./DocumentManager": @DocumentManager = {}
  11. "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
  12. "./Metrics": @Metrics =
  13. Timer: class Timer
  14. done: sinon.stub()
  15. @project_id = "project-id-123"
  16. @user_id = "user-id-123"
  17. @callback = sinon.stub()
  18. describe "updateProjectWithLocks", ->
  19. beforeEach ->
  20. @firstUpdate =
  21. id: 1
  22. update: 'foo'
  23. @secondUpdate =
  24. id: 2
  25. update: 'bar'
  26. @updates = [ @firstUpdate, @secondUpdate ]
  27. describe "successfully", ->
  28. beforeEach ->
  29. @DocumentManager.renameDocWithLock = sinon.stub().yields()
  30. @ProjectManager.updateProjectWithLocks @project_id, @user_id, @updates, @callback
  31. it "should rename the documents in the updates", ->
  32. @DocumentManager.renameDocWithLock
  33. .calledWith(@project_id, @firstUpdate.id, @user_id, @firstUpdate)
  34. .should.equal true
  35. @DocumentManager.renameDocWithLock
  36. .calledWith(@project_id, @secondUpdate.id, @user_id, @secondUpdate)
  37. .should.equal true
  38. it "should call the callback", ->
  39. @callback.called.should.equal true
  40. describe "when renaming a doc fails", ->
  41. beforeEach ->
  42. @error = new Error('error')
  43. @DocumentManager.renameDocWithLock = sinon.stub().yields(@error)
  44. @ProjectManager.updateProjectWithLocks @project_id, @user_id, @updates, @callback
  45. it "should call the callback with the error", ->
  46. @callback.calledWith(@error).should.equal true