PersistorManagerTests.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const { expect } = require('chai')
  2. const modulePath = '../../../app/js/PersistorManager.js'
  3. const SandboxedModule = require('sandboxed-module')
  4. describe('PersistorManager', function () {
  5. class FakePersistor {
  6. async sendStream() {
  7. return 'sent'
  8. }
  9. }
  10. describe('configured', function () {
  11. it('should return fake persistor', function () {
  12. const Settings = {
  13. docstore: {
  14. backend: 'gcs',
  15. bucket: 'wombat',
  16. },
  17. }
  18. const PersistorManger = SandboxedModule.require(modulePath, {
  19. requires: {
  20. '@overleaf/settings': Settings,
  21. '@overleaf/object-persistor': () => new FakePersistor(),
  22. '@overleaf/metrics': {},
  23. },
  24. })
  25. expect(PersistorManger).to.be.instanceof(FakePersistor)
  26. expect(PersistorManger.sendStream()).to.eventually.equal('sent')
  27. })
  28. })
  29. describe('not configured', function () {
  30. it('should return abstract persistor', async function () {
  31. const Settings = {
  32. docstore: {
  33. backend: undefined,
  34. bucket: 'wombat',
  35. },
  36. }
  37. const PersistorManger = SandboxedModule.require(modulePath, {
  38. requires: {
  39. '@overleaf/settings': Settings,
  40. '@overleaf/object-persistor': () => new FakePersistor(),
  41. '@overleaf/metrics': {},
  42. },
  43. })
  44. expect(PersistorManger.constructor.name).to.equal('AbstractPersistor')
  45. expect(PersistorManger.sendStream()).to.eventually.be.rejectedWith(
  46. /method not implemented in persistor/
  47. )
  48. })
  49. })
  50. })