PersistorManager.test.js 1.6 KB

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