Skip to content

Commit 831c2ee

Browse files
committed
Update the tests
1 parent 170dd40 commit 831c2ee

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

spec/RestCreate.spec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// These tests check the "create" functionality of the REST API.
1+
// These tests check the "create" / "update" functionality of the REST API.
22
var auth = require('../src/Auth');
33
var cache = require('../src/cache');
44
var Config = require('../src/Config');
@@ -41,6 +41,38 @@ describe('rest create', () => {
4141
});
4242
});
4343

44+
it('handles object and subdocument', (done) => {
45+
var obj = {
46+
subdoc: {foo: 'bar', wu: 'tan'},
47+
};
48+
rest.create(config, auth.nobody(config), 'MyClass', obj).then(() => {
49+
return database.mongoFind('MyClass', {}, {});
50+
}).then((results) => {
51+
expect(results.length).toEqual(1);
52+
var mob = results[0];
53+
expect(typeof mob.subdoc).toBe('object');
54+
expect(mob.subdoc.foo).toBe('bar');
55+
expect(mob.subdoc.wu).toBe('tan');
56+
expect(typeof mob._id).toEqual('string');
57+
58+
var obj = {
59+
'subdoc.wu': 'clan',
60+
};
61+
62+
rest.update(config, auth.nobody(config), 'MyClass', mob._id, obj).then(() => {
63+
return database.mongoFind('MyClass', {}, {});
64+
}).then((results) => {
65+
expect(results.length).toEqual(1);
66+
var mob = results[0];
67+
expect(typeof mob.subdoc).toBe('object');
68+
expect(mob.subdoc.foo).toBe('bar');
69+
expect(mob.subdoc.wu).toBe('clan');
70+
done();
71+
});
72+
73+
});
74+
});
75+
4476
it('handles user signup', (done) => {
4577
var user = {
4678
username: 'asdf',

spec/Schema.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ describe('Schema', () => {
3232
});
3333
});
3434

35+
it('can validate one object with dot notation', (done) => {
36+
config.database.loadSchema().then((schema) => {
37+
return schema.validateObject('TestObjectWithSubDoc', {x: false, y: 'YY', z: 1, 'aObject.k1': 'newValue'});
38+
}).then((schema) => {
39+
done();
40+
}, (error) => {
41+
fail(error);
42+
done();
43+
});
44+
});
45+
3546
it('can validate two objects in a row', (done) => {
3647
config.database.loadSchema().then((schema) => {
3748
return schema.validateObject('Foo', {x: true, y: 'yyy', z: 0});

0 commit comments

Comments
 (0)