BucketControllerTests.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. assert = require("chai").assert
  2. sinon = require('sinon')
  3. chai = require('chai')
  4. should = chai.should()
  5. expect = chai.expect
  6. modulePath = "../../../app/js/BucketController.js"
  7. SandboxedModule = require('sandboxed-module')
  8. describe "BucketController", ->
  9. beforeEach ->
  10. @PersistorManager =
  11. sendStream: sinon.stub()
  12. copyFile: sinon.stub()
  13. deleteFile:sinon.stub()
  14. @settings =
  15. s3:
  16. buckets:
  17. user_files:"user_files"
  18. filestore:
  19. backend: "s3"
  20. s3:
  21. secret: "secret"
  22. key: "this_key"
  23. @FileHandler =
  24. getFile: sinon.stub()
  25. deleteFile: sinon.stub()
  26. insertFile: sinon.stub()
  27. getDirectorySize: sinon.stub()
  28. @LocalFileWriter = {}
  29. @controller = SandboxedModule.require modulePath, requires:
  30. "./LocalFileWriter":@LocalFileWriter
  31. "./FileHandler": @FileHandler
  32. "./PersistorManager":@PersistorManager
  33. "settings-sharelatex": @settings
  34. "metrics-sharelatex":
  35. inc:->
  36. "logger-sharelatex":
  37. log:->
  38. err:->
  39. @project_id = "project_id"
  40. @file_id = "file_id"
  41. @bucket = "user_files"
  42. @key = "#{@project_id}/#{@file_id}"
  43. @req =
  44. query:{}
  45. params:
  46. bucket: @bucket
  47. 0: @key
  48. headers: {}
  49. @res =
  50. setHeader: ->
  51. @fileStream = {}
  52. describe "getFile", ->
  53. it "should pipe the stream", (done)->
  54. @FileHandler.getFile.callsArgWith(3, null, @fileStream)
  55. @fileStream.pipe = (res)=>
  56. res.should.equal @res
  57. done()
  58. @controller.getFile @req, @res
  59. it "should send a 500 if there is a problem", (done)->
  60. @FileHandler.getFile.callsArgWith(3, "error")
  61. @res.send = (code)=>
  62. code.should.equal 500
  63. done()
  64. @controller.getFile @req, @res