Skip to content

Commit

Permalink
fix: call SchemaController.getAllClasses with wrong type parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWu committed Nov 29, 2021
1 parent 35ac4c3 commit 0cdaab0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
82 changes: 82 additions & 0 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,51 @@ describe('schemas', () => {
});
});

it('ensure refresh cache after creating a class', async done => {
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(() => {
Expand Down Expand Up @@ -1507,6 +1552,43 @@ describe('schemas', () => {
});
});

it('ensure refresh cache after deleting a class', async done => {
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');
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/loaders/schemaQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const load = parseGraphQLSchema => {
enforceMasterKeyAccess(auth);

const schema = await config.database.loadSchema({ clearCache: true });
return (await schema.getAllClasses(true)).map(parseClass => ({
return (await schema.getAllClasses({ clearCache: true })).map(parseClass => ({
name: parseClass.className,
schemaFields: transformToGraphQL(parseClass.fields),
}));
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/SchemasRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }));
}

Expand Down

0 comments on commit 0cdaab0

Please sign in to comment.