Schema Cache Improvements (#5612)
* Cache Improvements * improve tests * more tests * clean-up * test with singlecache * ensure indexes exists * remove ALL_KEYS * Add Insert Test * enableSingleSchemaCache default true * Revert "enableSingleSchemaCache default true" This reverts commit 323e7130fb8f695e3ca44ebf9b3b1d38905353da. * further optimization * refactor enforceFieldExists * coverage improvements * improve tests * remove flaky test * cleanup * Learned something new
This commit is contained in:
@@ -1363,6 +1363,47 @@ describe('SchemaController', () => {
|
||||
.then(done)
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('setAllClasses return classes if cache fails', async () => {
|
||||
const schema = await config.database.loadSchema();
|
||||
|
||||
spyOn(schema._cache, 'setAllClasses').and.callFake(() =>
|
||||
Promise.reject('Oops!')
|
||||
);
|
||||
const errorSpy = spyOn(console, 'error').and.callFake(() => {});
|
||||
const allSchema = await schema.setAllClasses();
|
||||
|
||||
expect(allSchema).toBeDefined();
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
'Error saving schema to cache:',
|
||||
'Oops!'
|
||||
);
|
||||
});
|
||||
|
||||
it('should not throw on null field types', async () => {
|
||||
const schema = await config.database.loadSchema();
|
||||
const result = await schema.enforceFieldExists(
|
||||
'NewClass',
|
||||
'fieldName',
|
||||
null
|
||||
);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it('ensureFields should throw when schema is not set', async () => {
|
||||
const schema = await config.database.loadSchema();
|
||||
try {
|
||||
schema.ensureFields([
|
||||
{
|
||||
className: 'NewClass',
|
||||
fieldName: 'fieldName',
|
||||
type: 'String',
|
||||
},
|
||||
]);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe('Could not add field fieldName');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Class Level Permissions for requiredAuth', () => {
|
||||
|
||||
Reference in New Issue
Block a user