Added rest option: excludeKeys (#5737)

* Added restOption: excludeKeys

* improve tests
This commit is contained in:
Raschid J.F. Rafeally
2019-07-10 15:01:21 -05:00
committed by Diamond Lewis
parent 378e70afdc
commit 9816285205
3 changed files with 149 additions and 0 deletions

View File

@@ -3348,6 +3348,122 @@ describe('Parse.Query testing', () => {
}
);
});
it('exclude keys', async () => {
const obj = new TestObject({ foo: 'baz', hello: 'world' });
await obj.save();
const response = await request({
url: Parse.serverURL + '/classes/TestObject',
qs: {
excludeKeys: 'foo',
where: JSON.stringify({ objectId: obj.id }),
},
headers: masterKeyHeaders,
});
expect(response.data.results[0].foo).toBeUndefined();
expect(response.data.results[0].hello).toBe('world');
});
it('exclude keys with select same key', async () => {
const obj = new TestObject({ foo: 'baz', hello: 'world' });
await obj.save();
const response = await request({
url: Parse.serverURL + '/classes/TestObject',
qs: {
keys: 'foo',
excludeKeys: 'foo',
where: JSON.stringify({ objectId: obj.id }),
},
headers: masterKeyHeaders,
});
expect(response.data.results[0].foo).toBeUndefined();
expect(response.data.results[0].hello).toBeUndefined();
});
it('exclude keys with select different key', async () => {
const obj = new TestObject({ foo: 'baz', hello: 'world' });
await obj.save();
const response = await request({
url: Parse.serverURL + '/classes/TestObject',
qs: {
keys: 'foo,hello',
excludeKeys: 'foo',
where: JSON.stringify({ objectId: obj.id }),
},
headers: masterKeyHeaders,
});
expect(response.data.results[0].foo).toBeUndefined();
expect(response.data.results[0].hello).toBe('world');
});
it('exclude keys with include same key', async () => {
const pointer = new TestObject();
await pointer.save();
const obj = new TestObject({ child: pointer, hello: 'world' });
await obj.save();
const response = await request({
url: Parse.serverURL + '/classes/TestObject',
qs: {
include: 'child',
excludeKeys: 'child',
where: JSON.stringify({ objectId: obj.id }),
},
headers: masterKeyHeaders,
});
expect(response.data.results[0].child).toBeUndefined();
expect(response.data.results[0].hello).toBe('world');
});
it('exclude keys with include different key', async () => {
const pointer = new TestObject();
await pointer.save();
const obj = new TestObject({
child1: pointer,
child2: pointer,
hello: 'world',
});
await obj.save();
const response = await request({
url: Parse.serverURL + '/classes/TestObject',
qs: {
include: 'child1,child2',
excludeKeys: 'child1',
where: JSON.stringify({ objectId: obj.id }),
},
headers: masterKeyHeaders,
});
expect(response.data.results[0].child1).toBeUndefined();
expect(response.data.results[0].child2.objectId).toEqual(pointer.id);
expect(response.data.results[0].hello).toBe('world');
});
it('exclude keys with includeAll', async () => {
const pointer = new TestObject();
await pointer.save();
const obj = new TestObject({
child1: pointer,
child2: pointer,
hello: 'world',
});
await obj.save();
const response = await request({
url: Parse.serverURL + '/classes/TestObject',
qs: {
includeAll: true,
excludeKeys: 'child1',
where: JSON.stringify({ objectId: obj.id }),
},
headers: masterKeyHeaders,
});
expect(response.data.results[0].child).toBeUndefined();
expect(response.data.results[0].child2.objectId).toEqual(pointer.id);
expect(response.data.results[0].hello).toBe('world');
});
it('select keys with each query', function(done) {
const obj = new TestObject({ foo: 'baz', bar: 1 });