TemplatesControllerTests.coffee 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. sinon = require('sinon')
  6. modulePath = '../../../../app/js/Features/Templates/TemplatesController'
  7. describe 'TemplatesController', ->
  8. project_id = "213432"
  9. beforeEach ->
  10. @request = sinon.stub()
  11. @request.returns {
  12. pipe:->
  13. on:->
  14. }
  15. @fs = {
  16. unlink : sinon.stub()
  17. createWriteStream : sinon.stub().returns(on:(_, cb)->cb())
  18. }
  19. @ProjectUploadManager = {createProjectFromZipArchive : sinon.stub().callsArgWith(3, null, {_id:project_id})}
  20. @dumpFolder = "dump/path"
  21. @ProjectOptionsHandler = {setCompiler:sinon.stub().callsArgWith(2)}
  22. @uuid = "1234"
  23. @ProjectDetailsHandler =
  24. getProjectDescription:sinon.stub()
  25. @Project =
  26. update: sinon.stub().callsArgWith(3, null)
  27. @controller = SandboxedModule.require modulePath, requires:
  28. '../../../js/Features/Uploads/ProjectUploadManager':@ProjectUploadManager
  29. '../../../js/Features/Project/ProjectOptionsHandler':@ProjectOptionsHandler
  30. '../../../js/Features/Authentication/AuthenticationController': @AuthenticationController = {getLoggedInUserId: sinon.stub()}
  31. './TemplatesPublisher':@TemplatesPublisher
  32. "logger-sharelatex":
  33. log:->
  34. err:->
  35. "settings-sharelatex":
  36. path:
  37. dumpFolder:@dumpFolder
  38. siteUrl: @siteUrl = "http://localhost:3000"
  39. apis:
  40. v1:
  41. url: @v1Url="http://overleaf.com"
  42. user: "sharelatex"
  43. pass: "password"
  44. overleaf:
  45. host: @v1Url
  46. "uuid":v4:=>@uuid
  47. "request": @request
  48. "fs":@fs
  49. "../../../../app/js/models/Project": {Project: @Project}
  50. @zipUrl = "%2Ftemplates%2F52fb86a81ae1e566597a25f6%2Fv%2F4%2Fzip&templateName=Moderncv%20Banking&compiler=pdflatex"
  51. @templateName = "project name here"
  52. @user_id = "1234"
  53. @req =
  54. session:
  55. user: _id:@user_id
  56. templateData:
  57. zipUrl: @zipUrl
  58. templateName: @templateName
  59. @redirect = {}
  60. @AuthenticationController.getLoggedInUserId.returns(@user_id)
  61. describe 'v1Templates', ->
  62. it "should fetch zip from v1 based on template id", (done)->
  63. @templateVersionId = 15
  64. @req.body = {templateVersionId: @templateVersionId}
  65. redirect = =>
  66. @request.calledWith("#{@v1Url}/api/v1/sharelatex/templates/#{@templateVersionId}").should.equal true
  67. done()
  68. res = redirect:redirect
  69. @controller.createProjectFromV1Template @req, res