Skip to content

Commit e00112e

Browse files
committed
adds failing test for resolution
1 parent ad9495b commit e00112e

File tree

1 file changed

+63
-18
lines changed

1 file changed

+63
-18
lines changed

spec/ParseRelation.spec.js

+63-18
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ describe('Parse.Relation testing', () => {
237237
success: function(list) {
238238
equal(list.length, 1, "There should be only one result");
239239
equal(list[0].id, parent2.id,
240-
"Should have gotten back the right result");
240+
"Should have gotten back the right result");
241241
done();
242242
}
243243
});
@@ -246,7 +246,7 @@ describe('Parse.Relation testing', () => {
246246
}
247247
});
248248
});
249-
249+
250250
it("queries on relation fields with multiple ins", (done) => {
251251
var ChildObject = Parse.Object.extend("ChildObject");
252252
var childObjects = [];
@@ -268,7 +268,7 @@ describe('Parse.Relation testing', () => {
268268
relation2.add(childObjects[4]);
269269
relation2.add(childObjects[5]);
270270
relation2.add(childObjects[6]);
271-
271+
272272
var otherChild2 = parent2.relation("otherChild");
273273
otherChild2.add(childObjects[0]);
274274
otherChild2.add(childObjects[1]);
@@ -290,7 +290,7 @@ describe('Parse.Relation testing', () => {
290290
done();
291291
});
292292
});
293-
293+
294294
it("query on pointer and relation fields with equal", (done) => {
295295
var ChildObject = Parse.Object.extend("ChildObject");
296296
var childObjects = [];
@@ -306,29 +306,29 @@ describe('Parse.Relation testing', () => {
306306
relation.add(childObjects[0]);
307307
relation.add(childObjects[1]);
308308
relation.add(childObjects[2]);
309-
309+
310310
var parent2 = new ParentObject();
311311
parent2.set("x", 3);
312312
parent2.set("toChild", childObjects[2]);
313-
313+
314314
var parents = [];
315315
parents.push(parent);
316316
parents.push(parent2);
317317
parents.push(new ParentObject());
318-
318+
319319
return Parse.Object.saveAll(parents).then(() => {
320320
var query = new Parse.Query(ParentObject);
321321
query.equalTo("objectId", parent.id);
322322
query.equalTo("toChilds", childObjects[2]);
323-
323+
324324
return query.find().then((list) => {
325325
equal(list.length, 1, "There should be 1 result");
326326
done();
327327
});
328328
});
329329
});
330330
});
331-
331+
332332
it("query on pointer and relation fields with equal bis", (done) => {
333333
var ChildObject = Parse.Object.extend("ChildObject");
334334
var childObjects = [];
@@ -344,31 +344,31 @@ describe('Parse.Relation testing', () => {
344344
relation.add(childObjects[0]);
345345
relation.add(childObjects[1]);
346346
relation.add(childObjects[2]);
347-
347+
348348
var parent2 = new ParentObject();
349349
parent2.set("x", 3);
350350
parent2.relation("toChilds").add(childObjects[2]);
351-
351+
352352
var parents = [];
353353
parents.push(parent);
354354
parents.push(parent2);
355355
parents.push(new ParentObject());
356-
356+
357357
return Parse.Object.saveAll(parents).then(() => {
358358
var query = new Parse.Query(ParentObject);
359359
query.equalTo("objectId", parent2.id);
360360
// childObjects[2] is in 2 relations
361361
// before the fix, that woul yield 2 results
362362
query.equalTo("toChilds", childObjects[2]);
363-
363+
364364
return query.find().then((list) => {
365365
equal(list.length, 1, "There should be 1 result");
366366
done();
367367
});
368368
});
369369
});
370370
});
371-
371+
372372
it("or queries on pointer and relation fields", (done) => {
373373
var ChildObject = Parse.Object.extend("ChildObject");
374374
var childObjects = [];
@@ -384,16 +384,16 @@ describe('Parse.Relation testing', () => {
384384
relation.add(childObjects[0]);
385385
relation.add(childObjects[1]);
386386
relation.add(childObjects[2]);
387-
387+
388388
var parent2 = new ParentObject();
389389
parent2.set("x", 3);
390390
parent2.set("toChild", childObjects[2]);
391-
391+
392392
var parents = [];
393393
parents.push(parent);
394394
parents.push(parent2);
395395
parents.push(new ParentObject());
396-
396+
397397
return Parse.Object.saveAll(parents).then(() => {
398398
var query1 = new Parse.Query(ParentObject);
399399
query1.containedIn("toChilds", [childObjects[2]]);
@@ -501,5 +501,50 @@ describe('Parse.Relation testing', () => {
501501
});
502502
});
503503

504-
});
504+
notWorking('should properly get related objects with unfetched queries', (done) => {
505+
let objects = [];
506+
let owners = [];
507+
let allObjects = [];
508+
// Build 10 Objects and 10 owners
509+
while (objects.length != 10) {
510+
let object = new Parse.Object('AnObject');
511+
object.set({
512+
index: objects.length,
513+
even: objects.length % 2 == 0
514+
});
515+
objects.push(object);
516+
let owner = new Parse.Object('AnOwner');
517+
owners.push(owner);
518+
allObjects.push(object);
519+
allObjects.push(owner);
520+
}
521+
522+
let anotherOwner = new Parse.Object('AnotherOwner');
505523

524+
return Parse.Object.saveAll(allObjects.concat([anotherOwner])).then(() => {
525+
// put all the AnObject into the anotherOwner relationKey
526+
anotherOwner.relation('relationKey').add(objects);
527+
// Set each object[i] into owner[i];
528+
owners.forEach((owner,i) => {
529+
owner.set('key', objects[i]);
530+
});
531+
return Parse.Object.saveAll(owners.concat([anotherOwner]));
532+
}).then(() => {
533+
// Query on the relation of another owner
534+
let object = new Parse.Object('AnotherOwner');
535+
object.id = anotherOwner.id;
536+
let relationQuery = object.relation('relationKey').query();
537+
// Just get the even ones
538+
relationQuery.equalTo('even', true);
539+
// Make the query on anOwner
540+
let query = new Parse.Query('AnOwner');
541+
// where key match the relation query.
542+
query.matchesQuery('key', relationQuery);
543+
query.include('key');
544+
return query.find();
545+
}).then((results) => {
546+
expect(results.length).toBe(5);
547+
done();
548+
});
549+
});
550+
});

0 commit comments

Comments
 (0)