Skip to content

tests for troubleshooting #456 #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions spec/issue456.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@


describe("issue 456", () => {

it("should properly run promises together", (done) => {
const obj1 = new Parse.Object("ObjectA");
obj1.set({
"foo": "bar"
})

const obj2 = new Parse.Object("ObjectB");
obj2.set({
"bar": "baz"
});

Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => {
expect(obj1Again.get("foo")).toEqual("bar");
expect(obj2Again.get("bar")).toEqual("baz");
done();
}, function(err){
fail(err);
done();
});

})

it("should properly run query promises together", (done) => {
const obj1 = new Parse.Object("ObjectA");
obj1.set({
"foo": "bar"
})

const obj2 = new Parse.Object("ObjectB");
obj2.set({
"bar": "baz"
});

Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => {
expect(obj1Again.get("foo")).toEqual("bar");
expect(obj2Again.get("bar")).toEqual("baz");

const q1 = new Parse.Query("ObjectA");
const q2 = new Parse.Query("ObjectB");

return Parse.Promise.when(q1.first(), q2.first())

}).then((obj1Again, obj2Again) => {
expect(obj1Again.get("foo")).toEqual("bar");
expect(obj2Again.get("bar")).toEqual("baz");
done();
}).fail((err) => {
fail(err);
done();
});

});

it("should properly run query promises together in cloud code", (done) => {

Parse.Cloud.run("testRunQueriesTogether").then( (res) => {
expect(res.length).toBe(2);
expect(res[0].get("foo")).toEqual("bar");
expect(res[1].get("bar")).toEqual("baz");
done();
}).fail((err) => {
fail(err);
done();
});

})

it("should properly run query promises together in cloud code", (done) => {

Parse.Cloud.run("testCreateManyObjectInParallel").then( (res) => {
expect(res.length).toBe(2);
expect(res[0].length).toBe(200);
expect(res[1].length).toBe(200);
done();
}).fail((err) => {
fail(err);
done();
});
});
})
72 changes: 72 additions & 0 deletions src/cloud/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,75 @@ Parse.Cloud.define('requiredParameterCheck', function(req, res) {
}, function(params) {
return params.name;
});

Parse.Cloud.define("testRunQueriesTogether", (req, res) => {
const obj1 = new Parse.Object("ObjectA");
obj1.set({
"foo": "bar"
})

const obj2 = new Parse.Object("ObjectB");
obj2.set({
"bar": "baz"
});

Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => {
expect(obj1Again.get("foo")).toEqual("bar");
expect(obj2Again.get("bar")).toEqual("baz");

const q1 = new Parse.Query("ObjectA");
const q2 = new Parse.Query("ObjectB");

return Parse.Promise.when(q1.first(), q2.first())

}).then((obj1Again, obj2Again) => {
expect(obj1Again.get("foo")).toEqual("bar");
expect(obj2Again.get("bar")).toEqual("baz");
res.success([obj1Again, obj2Again]);
});
});

Parse.Cloud.define("testCreateManyObjectInParallel", (req, res) => {
var objects1 = [];
var objects2 = [];
// create 400 objects
for(var i=0; i<200; i++) {
var objA = new Parse.Object("ObjectA");
var objB = new Parse.Object("ObjectB");
objA.set({
index: i
})
objB.set({
index: i
})
objects1.push(objA);
objects2.push(objB);
}

// Gotta save dem all
var promises = [];
promises.push(Parse.Object.saveAll(objects1));
promises.push(Parse.Object.saveAll(objects2));
return Parse.Promise.when(promises).then(function(res){
if (res.length != 2) {
throw "Should have two results"
}
if (res[0].length != 200) {
throw "Should have saved 200 object on the 1st class"
}
if (res[1].length != 200) {
throw "Should have saved 200 object on the 2nd class"
}
var qA = new Parse.Query("ObjectA");
var qB = new Parse.Query("ObjectB");
qA.limit(1000);
qB.limit(1000);
var promises = [];
promises.push(qA.find());
promises.push(qB.find());
return Parse.Promise.when(promises);
}).then(function(results){
res.success(results);
})

})