ProjectDetailsHandlerTests.coffee 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. should = require('chai').should()
  2. modulePath = "../../../../app/js/Features/Project/ProjectDetailsHandler"
  3. SandboxedModule = require('sandboxed-module')
  4. sinon = require('sinon')
  5. assert = require("chai").assert
  6. require('chai').should()
  7. describe 'Project details handler', ->
  8. beforeEach ->
  9. @ProjectGetter =
  10. getProjectWithoutDocLines: sinon.stub()
  11. @ProjectModel =
  12. update: sinon.stub()
  13. @handler = SandboxedModule.require modulePath, requires:
  14. "./ProjectGetter":@ProjectGetter
  15. '../../models/Project': Project:@ProjectModel
  16. 'logger-sharelatex':
  17. log:->
  18. err:->
  19. @project_id = "321l3j1kjkjl"
  20. @project =
  21. name: "project"
  22. description: "this is a great project"
  23. something:"should not exist"
  24. compiler: "latexxxxxx"
  25. describe "getDetails", ->
  26. it "should find the project", (done)->
  27. @ProjectGetter.getProjectWithoutDocLines.callsArgWith(1, null, @project)
  28. @handler.getDetails @project_id, (err, details)=>
  29. details.name.should.equal @project.name
  30. details.description.should.equal @project.description
  31. details.compiler.should.equal @project.compiler
  32. assert.equal(details.something, undefined)
  33. done()
  34. it "should return the error", (done)->
  35. error = "some error"
  36. @ProjectGetter.getProjectWithoutDocLines.callsArgWith(1, error)
  37. @handler.getDetails @project_id, (err)=>
  38. err.should.equal error
  39. done()
  40. describe "setProjectDescription", ->
  41. beforeEach ->
  42. @description = "updated teh description"
  43. it "should update the project detials", (done)->
  44. @ProjectModel.update.callsArgWith(2)
  45. @handler.setProjectDescription @project_id, @description, =>
  46. @ProjectModel.update.calledWith({_id:@project_id}, {description:@description}).should.equal true
  47. done()