fix: schema cache not cleared in some cases (#7678)
This commit is contained in:
@@ -5,6 +5,7 @@ const dd = require('deep-diff');
|
|||||||
const Config = require('../lib/Config');
|
const Config = require('../lib/Config');
|
||||||
const request = require('../lib/request');
|
const request = require('../lib/request');
|
||||||
const TestUtils = require('../lib/TestUtils');
|
const TestUtils = require('../lib/TestUtils');
|
||||||
|
const SchemaController = require('../lib/Controllers/SchemaController').SchemaController;
|
||||||
|
|
||||||
let config;
|
let config;
|
||||||
|
|
||||||
@@ -239,6 +240,52 @@ describe('schemas', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ensure refresh cache after creating a class', async done => {
|
||||||
|
spyOn(SchemaController.prototype, 'reloadData').and.callFake(() => Promise.resolve());
|
||||||
|
await request({
|
||||||
|
url: 'http://localhost:8378/1/schemas',
|
||||||
|
method: 'POST',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
body: {
|
||||||
|
className: 'A',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const response = await request({
|
||||||
|
url: 'http://localhost:8378/1/schemas',
|
||||||
|
method: 'GET',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
const expected = {
|
||||||
|
results: [
|
||||||
|
userSchema,
|
||||||
|
roleSchema,
|
||||||
|
{
|
||||||
|
className: 'A',
|
||||||
|
fields: {
|
||||||
|
//Default fields
|
||||||
|
ACL: { type: 'ACL' },
|
||||||
|
createdAt: { type: 'Date' },
|
||||||
|
updatedAt: { type: 'Date' },
|
||||||
|
objectId: { type: 'String' },
|
||||||
|
},
|
||||||
|
classLevelPermissions: defaultClassLevelPermissions,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(
|
||||||
|
response.data.results
|
||||||
|
.sort((s1, s2) => s1.className.localeCompare(s2.className))
|
||||||
|
.map(s => {
|
||||||
|
const withoutIndexes = Object.assign({}, s);
|
||||||
|
delete withoutIndexes.indexes;
|
||||||
|
return withoutIndexes;
|
||||||
|
})
|
||||||
|
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('responds with a single schema', done => {
|
it('responds with a single schema', done => {
|
||||||
const obj = hasAllPODobject();
|
const obj = hasAllPODobject();
|
||||||
obj.save().then(() => {
|
obj.save().then(() => {
|
||||||
@@ -1507,6 +1554,46 @@ describe('schemas', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ensure refresh cache after deleting a class', async done => {
|
||||||
|
config = Config.get('test');
|
||||||
|
spyOn(config.schemaCache, 'del').and.callFake(() => {});
|
||||||
|
spyOn(SchemaController.prototype, 'reloadData').and.callFake(() => Promise.resolve());
|
||||||
|
await request({
|
||||||
|
url: 'http://localhost:8378/1/schemas',
|
||||||
|
method: 'POST',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
body: {
|
||||||
|
className: 'A',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await request({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: 'http://localhost:8378/1/schemas/A',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
const response = await request({
|
||||||
|
url: 'http://localhost:8378/1/schemas',
|
||||||
|
method: 'GET',
|
||||||
|
headers: masterKeyHeaders,
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
const expected = {
|
||||||
|
results: [userSchema, roleSchema],
|
||||||
|
};
|
||||||
|
expect(
|
||||||
|
response.data.results
|
||||||
|
.sort((s1, s2) => s1.className.localeCompare(s2.className))
|
||||||
|
.map(s => {
|
||||||
|
const withoutIndexes = Object.assign({}, s);
|
||||||
|
delete withoutIndexes.indexes;
|
||||||
|
return withoutIndexes;
|
||||||
|
})
|
||||||
|
).toEqual(expected.results.sort((s1, s2) => s1.className.localeCompare(s2.className)));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('deletes collections including join tables', done => {
|
it('deletes collections including join tables', done => {
|
||||||
const obj = new Parse.Object('MyClass');
|
const obj = new Parse.Object('MyClass');
|
||||||
obj.set('data', 'data');
|
obj.set('data', 'data');
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function classNameMismatchResponse(bodyClass, pathClass) {
|
|||||||
function getAllSchemas(req) {
|
function getAllSchemas(req) {
|
||||||
return req.config.database
|
return req.config.database
|
||||||
.loadSchema({ clearCache: true })
|
.loadSchema({ clearCache: true })
|
||||||
.then(schemaController => schemaController.getAllClasses(true))
|
.then(schemaController => schemaController.getAllClasses({ clearCache: true }))
|
||||||
.then(schemas => ({ response: { results: schemas } }));
|
.then(schemas => ({ response: { results: schemas } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user