2023-05-08 05:45:08 -04:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const modulePath = '../../../app/js/PersistorManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe('PersistorManager', function () {
|
|
|
|
class FakePersistor {
|
|
|
|
async sendStream() {
|
|
|
|
return 'sent'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('configured', function () {
|
|
|
|
it('should return fake persistor', function () {
|
|
|
|
const Settings = {
|
|
|
|
docstore: {
|
|
|
|
backend: 'gcs',
|
|
|
|
bucket: 'wombat',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const PersistorManger = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'@overleaf/settings': Settings,
|
|
|
|
'@overleaf/object-persistor': () => new FakePersistor(),
|
2023-05-23 04:10:44 -04:00
|
|
|
'@overleaf/metrics': {},
|
2023-05-08 05:45:08 -04:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(PersistorManger).to.be.instanceof(FakePersistor)
|
|
|
|
expect(PersistorManger.sendStream()).to.eventually.equal('sent')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('not configured', function () {
|
|
|
|
it('should return abstract persistor', async function () {
|
|
|
|
const Settings = {
|
|
|
|
docstore: {
|
|
|
|
backend: undefined,
|
|
|
|
bucket: 'wombat',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const PersistorManger = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'@overleaf/settings': Settings,
|
|
|
|
'@overleaf/object-persistor': () => new FakePersistor(),
|
2023-05-23 04:10:44 -04:00
|
|
|
'@overleaf/metrics': {},
|
2023-05-08 05:45:08 -04:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(PersistorManger.constructor.name).to.equal('AbstractPersistor')
|
|
|
|
expect(PersistorManger.sendStream()).to.eventually.be.rejectedWith(
|
|
|
|
/method not implemented in persistor/
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|