PersistorManagerTests.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. },
  23. })
  24. expect(PersistorManger).to.be.instanceof(FakePersistor)
  25. expect(PersistorManger.sendStream()).to.eventually.equal('sent')
  26. })
  27. })
  28. describe('not configured', function () {
  29. it('should return abstract persistor', async function () {
  30. const Settings = {
  31. docstore: {
  32. backend: undefined,
  33. bucket: 'wombat',
  34. },
  35. }
  36. const PersistorManger = SandboxedModule.require(modulePath, {
  37. requires: {
  38. '@overleaf/settings': Settings,
  39. '@overleaf/object-persistor': () => new FakePersistor(),
  40. },
  41. })
  42. expect(PersistorManger.constructor.name).to.equal('AbstractPersistor')
  43. expect(PersistorManger.sendStream()).to.eventually.be.rejectedWith(
  44. /method not implemented in persistor/
  45. )
  46. })
  47. })
  48. })