Skip to content

Commit cb07388

Browse files
committed
wip: tested CLP
1 parent 0aaf531 commit cb07388

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

spec/DefinedSchemas.spec.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,51 @@ describe('DefinedSchemas', () => {
366366
});
367367

368368
describe('ClassLevelPermissions', () => {
369-
xit('should save CLP');
370-
xit('should force disabled addField');
369+
fit('should use default CLP', async () => {
370+
const server = await reconfigureServer();
371+
const schemas = [{ className: 'Test' }];
372+
await new DefinedSchemas(schemas, server.config).execute();
373+
374+
const expectedTestCLP = {
375+
find: { '*': true },
376+
count: { '*': true },
377+
get: { '*': true },
378+
create: { '*': true },
379+
update: { '*': true },
380+
delete: { '*': true },
381+
addField: {},
382+
protectedFields: {},
383+
};
384+
let testSchema = await new Parse.Schema('Test').get();
385+
expect(testSchema.classLevelPermissions).toEqual(expectedTestCLP);
386+
387+
await new DefinedSchemas(schemas, server.config).execute();
388+
testSchema = await new Parse.Schema('Test').get();
389+
expect(testSchema.classLevelPermissions).toEqual(expectedTestCLP);
390+
});
391+
it('should force addField to empty', async () => {
392+
const server = await reconfigureServer();
393+
const schemas = [{ className: 'Test', classLevelPermissions: { addField: { '*': true } } }];
394+
await new DefinedSchemas(schemas, server.config).execute();
395+
396+
const expectedTestCLP = {
397+
find: { '*': true },
398+
count: { '*': true },
399+
get: { '*': true },
400+
create: { '*': true },
401+
update: { '*': true },
402+
delete: { '*': true },
403+
addField: {},
404+
protectedFields: {},
405+
};
406+
407+
let testSchema = await new Parse.Schema('Test').get();
408+
expect(testSchema.classLevelPermissions).toEqual(expectedTestCLP);
409+
410+
await new DefinedSchemas(schemas, server.config).execute();
411+
testSchema = await new Parse.Schema('Test').get();
412+
expect(testSchema.classLevelPermissions).toEqual(expectedTestCLP);
413+
});
371414
});
372415

373416
xit('should disable class endpoint when schemas provided to avoid dual source of truth');

src/DefinedSchemas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ export class DefinedSchemas {
5151
const timeout = setTimeout(() => {
5252
if (process.env.NODE_ENV === 'production') process.exit(1);
5353
}, 20000);
54-
this.allCloudSchemas = await Parse.Schema.all();
55-
clearTimeout(timeout);
5654
// Hack to force session schema to be created
5755
await this.createDeleteSession();
56+
this.allCloudSchemas = await Parse.Schema.all();
57+
clearTimeout(timeout);
5858
await Promise.all(this.localSchemas.map(async localSchema => this.saveOrUpdate(localSchema)));
5959
await this.enforceCLPForNonProvidedClass();
6060
} catch (e) {

0 commit comments

Comments
 (0)