Skip to content

Commit

Permalink
adds failing test for resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Mar 15, 2016
1 parent ad9495b commit e00112e
Showing 1 changed file with 63 additions and 18 deletions.
81 changes: 63 additions & 18 deletions spec/ParseRelation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('Parse.Relation testing', () => {
success: function(list) {
equal(list.length, 1, "There should be only one result");
equal(list[0].id, parent2.id,
"Should have gotten back the right result");
"Should have gotten back the right result");
done();
}
});
Expand All @@ -246,7 +246,7 @@ describe('Parse.Relation testing', () => {
}
});
});

it("queries on relation fields with multiple ins", (done) => {
var ChildObject = Parse.Object.extend("ChildObject");
var childObjects = [];
Expand All @@ -268,7 +268,7 @@ describe('Parse.Relation testing', () => {
relation2.add(childObjects[4]);
relation2.add(childObjects[5]);
relation2.add(childObjects[6]);

var otherChild2 = parent2.relation("otherChild");
otherChild2.add(childObjects[0]);
otherChild2.add(childObjects[1]);
Expand All @@ -290,7 +290,7 @@ describe('Parse.Relation testing', () => {
done();
});
});

it("query on pointer and relation fields with equal", (done) => {
var ChildObject = Parse.Object.extend("ChildObject");
var childObjects = [];
Expand All @@ -306,29 +306,29 @@ describe('Parse.Relation testing', () => {
relation.add(childObjects[0]);
relation.add(childObjects[1]);
relation.add(childObjects[2]);

var parent2 = new ParentObject();
parent2.set("x", 3);
parent2.set("toChild", childObjects[2]);

var parents = [];
parents.push(parent);
parents.push(parent2);
parents.push(new ParentObject());

return Parse.Object.saveAll(parents).then(() => {
var query = new Parse.Query(ParentObject);
query.equalTo("objectId", parent.id);
query.equalTo("toChilds", childObjects[2]);

return query.find().then((list) => {
equal(list.length, 1, "There should be 1 result");
done();
});
});
});
});

it("query on pointer and relation fields with equal bis", (done) => {
var ChildObject = Parse.Object.extend("ChildObject");
var childObjects = [];
Expand All @@ -344,31 +344,31 @@ describe('Parse.Relation testing', () => {
relation.add(childObjects[0]);
relation.add(childObjects[1]);
relation.add(childObjects[2]);

var parent2 = new ParentObject();
parent2.set("x", 3);
parent2.relation("toChilds").add(childObjects[2]);

var parents = [];
parents.push(parent);
parents.push(parent2);
parents.push(new ParentObject());

return Parse.Object.saveAll(parents).then(() => {
var query = new Parse.Query(ParentObject);
query.equalTo("objectId", parent2.id);
// childObjects[2] is in 2 relations
// before the fix, that woul yield 2 results
query.equalTo("toChilds", childObjects[2]);

return query.find().then((list) => {
equal(list.length, 1, "There should be 1 result");
done();
});
});
});
});

it("or queries on pointer and relation fields", (done) => {
var ChildObject = Parse.Object.extend("ChildObject");
var childObjects = [];
Expand All @@ -384,16 +384,16 @@ describe('Parse.Relation testing', () => {
relation.add(childObjects[0]);
relation.add(childObjects[1]);
relation.add(childObjects[2]);

var parent2 = new ParentObject();
parent2.set("x", 3);
parent2.set("toChild", childObjects[2]);

var parents = [];
parents.push(parent);
parents.push(parent2);
parents.push(new ParentObject());

return Parse.Object.saveAll(parents).then(() => {
var query1 = new Parse.Query(ParentObject);
query1.containedIn("toChilds", [childObjects[2]]);
Expand Down Expand Up @@ -501,5 +501,50 @@ describe('Parse.Relation testing', () => {
});
});

});
notWorking('should properly get related objects with unfetched queries', (done) => {
let objects = [];
let owners = [];
let allObjects = [];
// Build 10 Objects and 10 owners
while (objects.length != 10) {
let object = new Parse.Object('AnObject');
object.set({
index: objects.length,
even: objects.length % 2 == 0
});
objects.push(object);
let owner = new Parse.Object('AnOwner');
owners.push(owner);
allObjects.push(object);
allObjects.push(owner);
}

let anotherOwner = new Parse.Object('AnotherOwner');

return Parse.Object.saveAll(allObjects.concat([anotherOwner])).then(() => {
// put all the AnObject into the anotherOwner relationKey
anotherOwner.relation('relationKey').add(objects);
// Set each object[i] into owner[i];
owners.forEach((owner,i) => {
owner.set('key', objects[i]);
});
return Parse.Object.saveAll(owners.concat([anotherOwner]));
}).then(() => {
// Query on the relation of another owner
let object = new Parse.Object('AnotherOwner');
object.id = anotherOwner.id;
let relationQuery = object.relation('relationKey').query();
// Just get the even ones
relationQuery.equalTo('even', true);
// Make the query on anOwner
let query = new Parse.Query('AnOwner');
// where key match the relation query.
query.matchesQuery('key', relationQuery);
query.include('key');
return query.find();
}).then((results) => {
expect(results.length).toBe(5);
done();
});
});
});

0 comments on commit e00112e

Please sign in to comment.