Skip to content

Commit 430dd79

Browse files
committed
Add test cases for __type checking
1 parent f60c6af commit 430dd79

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

spec/ParseObject.spec.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,37 @@ describe('Parse.Object testing', () => {
335335
'Item should not be updated with invalid key.');
336336
item.save({ "foo^bar": "baz" }).then(fail, done);
337337
});
338-
338+
339339
it("invalid __type", function(done) {
340-
var item = new Parse.Object("Item");
341-
item.save({ "foo": {__type: "IvalidName"} }).then(fail, done);
340+
var item = new Parse.Object("Item");
341+
var types = ['Pointer', 'File', 'Date', 'GeoPoint', 'Bytes'];
342+
var Error = Parse.Error;
343+
var tests = types.map(type => {
344+
var test = new Parse.Object("Item");
345+
test.set('foo', {
346+
__type: type
347+
});
348+
return test;
349+
});
350+
var next = function(index) {
351+
if (index < tests.length) {
352+
tests[index].save().then(fail, error => {
353+
if (types[index] === 'Pointer') {
354+
expect(error.code).toEqual(Parse.Error.INVALID_POINTER);
355+
} else {
356+
expect(error.code).toEqual(Parse.Error.INCORRECT_TYPE);
357+
}
358+
next(index + 1);
359+
});
360+
} else {
361+
done();
362+
}
363+
}
364+
item.save({
365+
"foo": {
366+
__type: "IvalidName"
367+
}
368+
}).then(fail, err => next(0));
342369
});
343370

344371
it("simple field deletion", function(done) {

0 commit comments

Comments
 (0)