Files
kami-parse-server/spec/SchemaCache.spec.js
Florent Vilmart b754d51e8e chore(package): update jasmine to version 3.0.0 (#4553)
* chore(package): update jasmine to version 3.0.0

Closes #4547

* Fixes failing tests for jasmine 3.0

Starting 3.0, done(something) will fail

* Update tests so they dont leverage var, but let and const

With jasmine 3.0, the randomization engine was making the test fails because of the scope of `var`

* Remove randomizer

* Use same adapter for PG tests, drop table to ensure the tests dont side effect
2018-02-17 09:55:30 -05:00

69 lines
2.2 KiB
JavaScript

const CacheController = require('../src/Controllers/CacheController.js').default;
const InMemoryCacheAdapter = require('../src/Adapters/Cache/InMemoryCacheAdapter').default;
const SchemaCache = require('../src/Controllers/SchemaCache').default;
describe('SchemaCache', () => {
let cacheController;
beforeEach(() => {
const cacheAdapter = new InMemoryCacheAdapter({});
cacheController = new CacheController(cacheAdapter, 'appId');
});
it('can retrieve a single schema after all schemas stored', (done) => {
const schemaCache = new SchemaCache(cacheController);
const allSchemas = [{
className: 'Class1'
}, {
className: 'Class2'
}];
schemaCache.setAllClasses(allSchemas).then(() => {
return schemaCache.getOneSchema('Class2');
}).then((schema) => {
expect(schema).not.toBeNull();
done();
});
});
it('does not return all schemas after a single schema is stored', (done) => {
const schemaCache = new SchemaCache(cacheController);
const schema = {
className: 'Class1'
};
schemaCache.setOneSchema(schema.className, schema).then(() => {
return schemaCache.getAllClasses();
}).then((allSchemas) => {
expect(allSchemas).toBeNull();
done();
});
});
it('doesn\'t persist cached data by default', (done) => {
const schemaCache = new SchemaCache(cacheController);
const schema = {
className: 'Class1'
};
schemaCache.setOneSchema(schema.className, schema).then(() => {
const anotherSchemaCache = new SchemaCache(cacheController);
return anotherSchemaCache.getOneSchema(schema.className).then((schema) => {
expect(schema).toBeNull();
done();
});
});
});
it('can persist cached data', (done) => {
const schemaCache = new SchemaCache(cacheController, 5000, true);
const schema = {
className: 'Class1'
};
schemaCache.setOneSchema(schema.className, schema).then(() => {
const anotherSchemaCache = new SchemaCache(cacheController, 5000, true);
return anotherSchemaCache.getOneSchema(schema.className).then((schema) => {
expect(schema).not.toBeNull();
done();
});
});
});
});