PersistorManagerTests.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const sinon = require('sinon')
  2. const chai = require('chai')
  3. const { expect } = chai
  4. const SandboxedModule = require('sandboxed-module')
  5. const modulePath = '../../../app/js/PersistorManager.js'
  6. describe('PersistorManager', function() {
  7. let PersistorManager, FSPersistor, S3Persistor, settings, requires
  8. beforeEach(function() {
  9. FSPersistor = {
  10. wrappedMethod: sinon.stub().returns('FSPersistor')
  11. }
  12. S3Persistor = {
  13. wrappedMethod: sinon.stub().returns('S3Persistor')
  14. }
  15. settings = {
  16. filestore: {}
  17. }
  18. requires = {
  19. './S3Persistor': S3Persistor,
  20. './FSPersistor': FSPersistor,
  21. 'settings-sharelatex': settings,
  22. 'logger-sharelatex': {
  23. log() {},
  24. err() {}
  25. }
  26. }
  27. })
  28. it('should implement the S3 wrapped method when S3 is configured', function() {
  29. settings.filestore.backend = 's3'
  30. PersistorManager = SandboxedModule.require(modulePath, { requires })
  31. expect(PersistorManager).to.respondTo('wrappedMethod')
  32. expect(PersistorManager.wrappedMethod()).to.equal('S3Persistor')
  33. })
  34. it("should implement the S3 wrapped method when 'aws-sdk' is configured", function() {
  35. settings.filestore.backend = 'aws-sdk'
  36. PersistorManager = SandboxedModule.require(modulePath, { requires })
  37. expect(PersistorManager).to.respondTo('wrappedMethod')
  38. expect(PersistorManager.wrappedMethod()).to.equal('S3Persistor')
  39. })
  40. it('should implement the FS wrapped method when FS is configured', function() {
  41. settings.filestore.backend = 'fs'
  42. PersistorManager = SandboxedModule.require(modulePath, { requires })
  43. expect(PersistorManager).to.respondTo('wrappedMethod')
  44. expect(PersistorManager.wrappedMethod()).to.equal('FSPersistor')
  45. })
  46. it('should throw an error when the backend is not configured', function() {
  47. try {
  48. SandboxedModule.require(modulePath, { requires })
  49. } catch (err) {
  50. expect(err.message).to.equal('no backend specified - config incomplete')
  51. return
  52. }
  53. expect('should have caught an error').not.to.exist
  54. })
  55. it('should throw an error when the backend is unknown', function() {
  56. settings.filestore.backend = 'magic'
  57. try {
  58. SandboxedModule.require(modulePath, { requires })
  59. } catch (err) {
  60. expect(err.message).to.equal('unknown filestore backend: magic')
  61. return
  62. }
  63. expect('should have caught an error').not.to.exist
  64. })
  65. })