PersistorManagerTests.js 2.1 KB

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