BucketControllerTests.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* eslint-disable
  2. no-return-assign,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const { assert } = require('chai')
  13. const sinon = require('sinon')
  14. const chai = require('chai')
  15. const should = chai.should()
  16. const { expect } = chai
  17. const modulePath = '../../../app/js/BucketController.js'
  18. const SandboxedModule = require('sandboxed-module')
  19. describe('BucketController', function() {
  20. beforeEach(function() {
  21. this.PersistorManager = {
  22. sendStream: sinon.stub(),
  23. copyFile: sinon.stub(),
  24. deleteFile: sinon.stub()
  25. }
  26. this.settings = {
  27. s3: {
  28. buckets: {
  29. user_files: 'user_files'
  30. }
  31. },
  32. filestore: {
  33. backend: 's3',
  34. s3: {
  35. secret: 'secret',
  36. key: 'this_key'
  37. }
  38. }
  39. }
  40. this.FileHandler = {
  41. getFile: sinon.stub(),
  42. deleteFile: sinon.stub(),
  43. insertFile: sinon.stub(),
  44. getDirectorySize: sinon.stub()
  45. }
  46. this.LocalFileWriter = {}
  47. this.controller = SandboxedModule.require(modulePath, {
  48. requires: {
  49. './LocalFileWriter': this.LocalFileWriter,
  50. './FileHandler': this.FileHandler,
  51. './PersistorManager': this.PersistorManager,
  52. 'settings-sharelatex': this.settings,
  53. 'metrics-sharelatex': {
  54. inc() {}
  55. },
  56. 'logger-sharelatex': {
  57. log() {},
  58. err() {}
  59. }
  60. }
  61. })
  62. this.project_id = 'project_id'
  63. this.file_id = 'file_id'
  64. this.bucket = 'user_files'
  65. this.key = `${this.project_id}/${this.file_id}`
  66. this.req = {
  67. query: {},
  68. params: {
  69. bucket: this.bucket,
  70. 0: this.key
  71. },
  72. headers: {}
  73. }
  74. this.res = { setHeader() {} }
  75. return (this.fileStream = {})
  76. })
  77. return describe('getFile', function() {
  78. it('should pipe the stream', function(done) {
  79. this.FileHandler.getFile.callsArgWith(3, null, this.fileStream)
  80. this.fileStream.pipe = res => {
  81. res.should.equal(this.res)
  82. return done()
  83. }
  84. return this.controller.getFile(this.req, this.res)
  85. })
  86. return it('should send a 500 if there is a problem', function(done) {
  87. this.FileHandler.getFile.callsArgWith(3, 'error')
  88. this.res.send = code => {
  89. code.should.equal(500)
  90. return done()
  91. }
  92. return this.controller.getFile(this.req, this.res)
  93. })
  94. })
  95. })