Skip to content

Commit 2d61b7f

Browse files
authored
Merge branch 'master' into LDS
2 parents 5a6c779 + 1353997 commit 2d61b7f

14 files changed

+1583
-832
lines changed

2.0.0.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,15 @@ Promise.all([promise1, promise2, promise3])
9191

9292
});
9393
```
94+
95+
:warning: Whereas `Parse.Promise.always`, `Promise.finally` callback don't receive any arguments, and don't resolve with a new argument to pass to the next promise in chain.
96+
97+
```js
98+
// before
99+
Parse.Promise.as(1).always((val) => val + 1).then((result) => console.log(result))
100+
// will print 2
101+
102+
// after
103+
Promise.resolve(1).finally(() => 2).then((result) => console.log(result))
104+
// will print 1
105+
```

integration/test/ParseObjectTest.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,93 @@ describe('Parse Object', () => {
13471347
});
13481348
});
13491349

1350+
it('can fetchWithInclude', async () => {
1351+
const parent = new TestObject();
1352+
const child = new TestObject();
1353+
child.set('field', 'isChild');
1354+
parent.set('child', child);
1355+
await parent.save();
1356+
1357+
const obj1 = TestObject.createWithoutData(parent.id);
1358+
const fetchedObj1 = await obj1.fetchWithInclude('child');
1359+
assert.equal(obj1.get('child').get('field'), 'isChild');
1360+
assert.equal(fetchedObj1.get('child').get('field'), 'isChild');
1361+
1362+
const obj2 = TestObject.createWithoutData(parent.id);
1363+
const fetchedObj2 = await obj2.fetchWithInclude(['child']);
1364+
assert.equal(obj2.get('child').get('field'), 'isChild');
1365+
assert.equal(fetchedObj2.get('child').get('field'), 'isChild');
1366+
1367+
const obj3 = TestObject.createWithoutData(parent.id);
1368+
const fetchedObj3 = await obj3.fetchWithInclude([ ['child'] ]);
1369+
assert.equal(obj3.get('child').get('field'), 'isChild');
1370+
assert.equal(fetchedObj3.get('child').get('field'), 'isChild');
1371+
});
1372+
1373+
it('can fetchWithInclude dot notation', async () => {
1374+
const parent = new TestObject();
1375+
const child = new TestObject();
1376+
const grandchild = new TestObject();
1377+
grandchild.set('field', 'isGrandchild');
1378+
child.set('grandchild', grandchild);
1379+
parent.set('child', child);
1380+
await Parse.Object.saveAll([parent, child, grandchild]);
1381+
1382+
const obj1 = TestObject.createWithoutData(parent.id);
1383+
await obj1.fetchWithInclude('child.grandchild');
1384+
assert.equal(obj1.get('child').get('grandchild').get('field'), 'isGrandchild');
1385+
1386+
const obj2 = TestObject.createWithoutData(parent.id);
1387+
await obj2.fetchWithInclude(['child.grandchild']);
1388+
assert.equal(obj2.get('child').get('grandchild').get('field'), 'isGrandchild');
1389+
1390+
const obj3 = TestObject.createWithoutData(parent.id);
1391+
await obj3.fetchWithInclude([ ['child.grandchild'] ]);
1392+
assert.equal(obj3.get('child').get('grandchild').get('field'), 'isGrandchild');
1393+
});
1394+
1395+
it('can fetchAllWithInclude', async () => {
1396+
const parent = new TestObject();
1397+
const child = new TestObject();
1398+
child.set('field', 'isChild');
1399+
parent.set('child', child);
1400+
await parent.save();
1401+
1402+
const obj1 = TestObject.createWithoutData(parent.id);
1403+
await Parse.Object.fetchAllWithInclude([obj1], 'child');
1404+
assert.equal(obj1.get('child').get('field'), 'isChild');
1405+
1406+
const obj2 = TestObject.createWithoutData(parent.id);
1407+
await Parse.Object.fetchAllWithInclude([obj2], ['child']);
1408+
assert.equal(obj2.get('child').get('field'), 'isChild');
1409+
1410+
const obj3 = TestObject.createWithoutData(parent.id);
1411+
await Parse.Object.fetchAllWithInclude([obj3], [ ['child'] ]);
1412+
assert.equal(obj3.get('child').get('field'), 'isChild');
1413+
});
1414+
1415+
it('can fetchAllWithInclude dot notation', async () => {
1416+
const parent = new TestObject();
1417+
const child = new TestObject();
1418+
const grandchild = new TestObject();
1419+
grandchild.set('field', 'isGrandchild');
1420+
child.set('grandchild', grandchild);
1421+
parent.set('child', child);
1422+
await Parse.Object.saveAll([parent, child, grandchild]);
1423+
1424+
const obj1 = TestObject.createWithoutData(parent.id);
1425+
await Parse.Object.fetchAllWithInclude([obj1], 'child.grandchild');
1426+
assert.equal(obj1.get('child').get('grandchild').get('field'), 'isGrandchild');
1427+
1428+
const obj2 = TestObject.createWithoutData(parent.id);
1429+
await Parse.Object.fetchAllWithInclude([obj2], ['child.grandchild']);
1430+
assert.equal(obj2.get('child').get('grandchild').get('field'), 'isGrandchild');
1431+
1432+
const obj3 = TestObject.createWithoutData(parent.id);
1433+
await Parse.Object.fetchAllWithInclude([obj3], [ ['child.grandchild'] ]);
1434+
assert.equal(obj3.get('child').get('grandchild').get('field'), 'isGrandchild');
1435+
});
1436+
13501437
it('fires errors when readonly attributes are changed', (done) => {
13511438
let LimitedObject = Parse.Object.extend('LimitedObject');
13521439
LimitedObject.readOnlyAttributes = function() {

integration/test/ParseQueryTest.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,53 @@ describe('Parse Query', () => {
196196
});
197197
});
198198

199+
it('can do containedBy queries with numbers', async () => {
200+
const NumberSet = Parse.Object.extend('NumberSet');
201+
const objectsList = [];
202+
objectsList.push(new NumberSet({ numbers: [0, 1, 2] }));
203+
objectsList.push(new NumberSet({ numbers: [2, 0] }));
204+
objectsList.push(new NumberSet({ numbers: [1, 2, 3, 4] }));
205+
206+
await Parse.Object.saveAll(objectsList);
207+
208+
const query = new Parse.Query(NumberSet);
209+
query.containedBy('numbers', [1, 2, 3, 4, 5]);
210+
const results = await query.find();
211+
assert.equal(results.length, 1);
212+
});
213+
214+
it('can do containedBy queries with pointer', async () => {
215+
const objects = Array.from(Array(10).keys()).map((idx) => {
216+
const obj = new Parse.Object('Object');
217+
obj.set('key', idx);
218+
return obj;
219+
});
220+
221+
const parent1 = new Parse.Object('Parent');
222+
const parent2 = new Parse.Object('Parent');
223+
const parent3 = new Parse.Object('Parent');
224+
225+
await Parse.Object.saveAll(objects);
226+
227+
// [0, 1, 2]
228+
parent1.set('objects', objects.slice(0, 3));
229+
230+
const shift = objects.shift();
231+
// [2, 0]
232+
parent2.set('objects', [objects[1], shift]);
233+
234+
// [1, 2, 3, 4]
235+
parent3.set('objects', objects.slice(1, 4));
236+
237+
await Parse.Object.saveAll([parent1, parent2, parent3]);
238+
const query = new Parse.Query('Parent');
239+
query.containedBy('objects', objects);
240+
const results = await query.find();
241+
242+
assert.equal(results.length, 1);
243+
assert.equal(results[0].id, parent3.id);
244+
});
245+
199246
it('can do equalTo queries', (done) => {
200247
let query = new Parse.Query('BoxedNumber');
201248
query.equalTo('number', 3);
@@ -1022,6 +1069,50 @@ describe('Parse Query', () => {
10221069
});
10231070
});
10241071

1072+
it('can includeAll nested objects', async () => {
1073+
const child1 = new TestObject({ foo: 'bar' });
1074+
const child2 = new TestObject({ foo: 'baz' });
1075+
const child3 = new TestObject({ foo: 'bin' });
1076+
const parent = new Parse.Object('Container');
1077+
parent.set('child1', child1);
1078+
parent.set('child2', child2);
1079+
parent.set('child3', child3);
1080+
await Parse.Object.saveAll([child1, child2, child3, parent]);
1081+
1082+
const query = new Parse.Query('Container');
1083+
query.equalTo('objectId', parent.id);
1084+
query.includeAll();
1085+
1086+
const results = await query.find();
1087+
1088+
assert.equal(results.length, 1);
1089+
const parentAgain = results[0];
1090+
assert.equal(parentAgain.get('child1').get('foo'), 'bar');
1091+
assert.equal(parentAgain.get('child2').get('foo'), 'baz');
1092+
assert.equal(parentAgain.get('child3').get('foo'), 'bin');
1093+
});
1094+
1095+
it('can includeAll nested objects in .each', async () => {
1096+
const child1 = new TestObject({ foo: 'bar' });
1097+
const child2 = new TestObject({ foo: 'baz' });
1098+
const child3 = new TestObject({ foo: 'bin' });
1099+
const parent = new Parse.Object('Container');
1100+
parent.set('child1', child1);
1101+
parent.set('child2', child2);
1102+
parent.set('child3', child3);
1103+
await Parse.Object.saveAll([child1, child2, child3, parent]);
1104+
1105+
const query = new Parse.Query('Container');
1106+
query.equalTo('objectId', parent.id);
1107+
query.includeAll();
1108+
1109+
await query.each((obj) => {
1110+
assert.equal(obj.get('child1').get('foo'), 'bar');
1111+
assert.equal(obj.get('child2').get('foo'), 'baz');
1112+
assert.equal(obj.get('child3').get('foo'), 'bin');
1113+
});
1114+
});
1115+
10251116
it('can include nested objects via array', (done) => {
10261117
let child = new TestObject();
10271118
let parent = new Parse.Object('Container');
@@ -1367,6 +1458,55 @@ describe('Parse Query', () => {
13671458
}).catch(e => console.log(e));
13681459
});
13691460

1461+
it('can build NOR queries', async () => {
1462+
const objects = [];
1463+
for (let i = 0; i < 10; i += 1) {
1464+
const obj = new Parse.Object('NORTest');
1465+
obj.set({ x: i });
1466+
objects.push(obj);
1467+
}
1468+
await Parse.Object.saveAll(objects);
1469+
1470+
const q1 = new Parse.Query('NORTest');
1471+
q1.greaterThan('x', 5);
1472+
const q2 = new Parse.Query('NORTest');
1473+
q2.lessThan('x', 3);
1474+
const norQuery = Parse.Query.nor(q1, q2);
1475+
const results = await norQuery.find();
1476+
1477+
assert.equal(results.length, 3);
1478+
results.forEach((number) => {
1479+
assert(number.get('x') >= 3 && number.get('x') <= 5);
1480+
});
1481+
});
1482+
1483+
it('can build complex NOR queries', async () => {
1484+
const objects = [];
1485+
for (let i = 0; i < 10; i += 1) {
1486+
const child = new Parse.Object('Child');
1487+
child.set('x', i);
1488+
const parent = new Parse.Object('Parent');
1489+
parent.set('child', child);
1490+
parent.set('y', i);
1491+
objects.push(parent);
1492+
}
1493+
await Parse.Object.saveAll(objects);
1494+
1495+
const subQuery = new Parse.Query('Child');
1496+
subQuery.equalTo('x', 4);
1497+
const q1 = new Parse.Query('Parent');
1498+
q1.matchesQuery('child', subQuery);
1499+
const q2 = new Parse.Query('Parent');
1500+
q2.equalTo('y', 5);
1501+
const norQuery = new Parse.Query.nor(q1, q2);
1502+
const results = await norQuery.find();
1503+
1504+
assert.equal(results.length, 8);
1505+
results.forEach((number) => {
1506+
assert(number.get('x') !== 4 || number.get('x') !== 5);
1507+
});
1508+
});
1509+
13701510
it('can iterate over results with each', (done) => {
13711511
let items = [];
13721512
for (let i = 0; i < 50; i++) {

integration/test/ParseUserTest.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,55 @@ describe('Parse User', () => {
193193
});
194194
});
195195

196+
it('can fetch non-auth user with include', async () => {
197+
Parse.User.enableUnsafeCurrentUser();
198+
199+
const child = new Parse.Object('TestObject');
200+
child.set('field', 'test');
201+
let user = new Parse.User();
202+
user.set('password', 'asdf');
203+
user.set('email', '[email protected]');
204+
user.set('username', 'zxcv');
205+
user.set('child', child);
206+
await user.signUp();
207+
208+
const query = new Parse.Query(Parse.User);
209+
const userNotAuthed = await query.get(user.id);
210+
211+
assert.equal(userNotAuthed.get('child').get('field'), undefined);
212+
213+
const fetchedUser = await userNotAuthed.fetchWithInclude('child');
214+
215+
assert.equal(userNotAuthed.get('child').get('field'), 'test');
216+
assert.equal(fetchedUser.get('child').get('field'), 'test');
217+
});
218+
219+
it('can fetch auth user with include', async () => {
220+
Parse.User.enableUnsafeCurrentUser();
221+
222+
const child = new Parse.Object('TestObject');
223+
child.set('field', 'test');
224+
let user = new Parse.User();
225+
user.set('password', 'asdf');
226+
user.set('email', '[email protected]');
227+
user.set('username', 'zxcv');
228+
user.set('child', child);
229+
await user.signUp();
230+
231+
user = await Parse.User.logIn('zxcv', 'asdf');
232+
233+
assert.equal(user.get('child').get('field'), undefined);
234+
assert.equal(Parse.User.current().get('child').get('field'), undefined);
235+
236+
const fetchedUser = await user.fetchWithInclude('child');
237+
const current = await Parse.User.currentAsync();
238+
239+
assert.equal(user.get('child').get('field'), 'test');
240+
assert.equal(current.get('child').get('field'), 'test');
241+
assert.equal(fetchedUser.get('child').get('field'), 'test');
242+
assert.equal(Parse.User.current().get('child').get('field'), 'test');
243+
});
244+
196245
it('can store the current user', (done) => {
197246
Parse.User.enableUnsafeCurrentUser();
198247
let user = new Parse.User();

jsdoc-conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"opts": {
1818
"recurse": true,
19-
"template": "node_modules/minami",
19+
"template": "node_modules/@parse/minami",
2020
"showInheritedInNav": true,
2121
"useLongnameInNav": true
2222
}

0 commit comments

Comments
 (0)