forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchemaCache.spec.js
68 lines (62 loc) · 2.16 KB
/
SchemaCache.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var CacheController = require('../src/Controllers/CacheController.js').default;
var InMemoryCacheAdapter = require('../src/Adapters/Cache/InMemoryCacheAdapter').default;
var 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();
});
});
});
});