fix: schema cache not cleared in some cases (#7771)

This commit is contained in:
Manuel
2022-01-13 03:04:49 +01:00
committed by GitHub
parent 66347dc44a
commit 3b92fa1ca9
2 changed files with 88 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ const dd = require('deep-diff');
const Config = require('../lib/Config');
const request = require('../lib/request');
const TestUtils = require('../lib/TestUtils');
const SchemaController = require('../lib/Controllers/SchemaController').SchemaController;
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 => {
const obj = hasAllPODobject();
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 => {
const obj = new Parse.Object('MyClass');
obj.set('data', 'data');

View File

@@ -16,7 +16,7 @@ function classNameMismatchResponse(bodyClass, pathClass) {
function getAllSchemas(req) {
return req.config.database
.loadSchema({ clearCache: true })
.then(schemaController => schemaController.getAllClasses(true))
.then(schemaController => schemaController.getAllClasses({ clearCache: true }))
.then(schemas => ({ response: { results: schemas } }));
}