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:
Diamond Lewis
2019-05-24 16:42:27 -05:00
committed by GitHub
parent cae858e16a
commit f7716f2f87
9 changed files with 404 additions and 178 deletions

View File

@@ -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', () => {