From 430dd7944e23ad5c2c2d8a7c726d10d7a2fea936 Mon Sep 17 00:00:00 2001 From: Jim Lin Date: Sun, 28 Feb 2016 16:08:26 +0800 Subject: [PATCH] Add test cases for __type checking --- spec/ParseObject.spec.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/spec/ParseObject.spec.js b/spec/ParseObject.spec.js index 10a44e9f..ccd8920c 100644 --- a/spec/ParseObject.spec.js +++ b/spec/ParseObject.spec.js @@ -335,10 +335,37 @@ describe('Parse.Object testing', () => { 'Item should not be updated with invalid key.'); item.save({ "foo^bar": "baz" }).then(fail, done); }); - + it("invalid __type", function(done) { - var item = new Parse.Object("Item"); - item.save({ "foo": {__type: "IvalidName"} }).then(fail, done); + var item = new Parse.Object("Item"); + var types = ['Pointer', 'File', 'Date', 'GeoPoint', 'Bytes']; + var Error = Parse.Error; + var tests = types.map(type => { + var test = new Parse.Object("Item"); + test.set('foo', { + __type: type + }); + return test; + }); + var next = function(index) { + if (index < tests.length) { + tests[index].save().then(fail, error => { + if (types[index] === 'Pointer') { + expect(error.code).toEqual(Parse.Error.INVALID_POINTER); + } else { + expect(error.code).toEqual(Parse.Error.INCORRECT_TYPE); + } + next(index + 1); + }); + } else { + done(); + } + } + item.save({ + "foo": { + __type: "IvalidName" + } + }).then(fail, err => next(0)); }); it("simple field deletion", function(done) {