diff --git a/spec/RestCreate.spec.js b/spec/RestCreate.spec.js index f4055974..1e79d2bf 100644 --- a/spec/RestCreate.spec.js +++ b/spec/RestCreate.spec.js @@ -1,4 +1,4 @@ -// These tests check the "create" functionality of the REST API. +// These tests check the "create" / "update" functionality of the REST API. var auth = require('../src/Auth'); var cache = require('../src/cache'); var Config = require('../src/Config'); @@ -41,6 +41,38 @@ describe('rest create', () => { }); }); + it('handles object and subdocument', (done) => { + var obj = { + subdoc: {foo: 'bar', wu: 'tan'}, + }; + rest.create(config, auth.nobody(config), 'MyClass', obj).then(() => { + return database.mongoFind('MyClass', {}, {}); + }).then((results) => { + expect(results.length).toEqual(1); + var mob = results[0]; + expect(typeof mob.subdoc).toBe('object'); + expect(mob.subdoc.foo).toBe('bar'); + expect(mob.subdoc.wu).toBe('tan'); + expect(typeof mob._id).toEqual('string'); + + var obj = { + 'subdoc.wu': 'clan', + }; + + rest.update(config, auth.nobody(config), 'MyClass', mob._id, obj).then(() => { + return database.mongoFind('MyClass', {}, {}); + }).then((results) => { + expect(results.length).toEqual(1); + var mob = results[0]; + expect(typeof mob.subdoc).toBe('object'); + expect(mob.subdoc.foo).toBe('bar'); + expect(mob.subdoc.wu).toBe('clan'); + done(); + }); + + }); + }); + it('handles user signup', (done) => { var user = { username: 'asdf', diff --git a/spec/Schema.spec.js b/spec/Schema.spec.js index a5c28c5b..8be0a02e 100644 --- a/spec/Schema.spec.js +++ b/spec/Schema.spec.js @@ -32,6 +32,17 @@ describe('Schema', () => { }); }); + it('can validate one object with dot notation', (done) => { + config.database.loadSchema().then((schema) => { + return schema.validateObject('TestObjectWithSubDoc', {x: false, y: 'YY', z: 1, 'aObject.k1': 'newValue'}); + }).then((schema) => { + done(); + }, (error) => { + fail(error); + done(); + }); + }); + it('can validate two objects in a row', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('Foo', {x: true, y: 'yyy', z: 0});