Skip to content

Commit 096128b

Browse files
authored
Merge pull request #3 from teslitsky/master
Add test case for nested object saving and updating doc with $
2 parents 310e5f9 + e93d635 commit 096128b

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

tests/task.tests.js

+51-7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ module.exports = describe("Task", function(){
5757
});
5858
});
5959

60+
describe("#save nested object", function(){
61+
it("should save successfully with model", function(){
62+
var nested = new TestMdlA({name: "Nested User 1", info: {foo: 'bar', some: 'string'}});
63+
64+
return task.save(TestMdlA, nested).run();
65+
});
66+
67+
it("should have Nested User in " + TEST_COLLECTION_A, function(){
68+
return expect(TestMdlA.find({name: "Nested User 1", 'info.foo': 'bar'}).exec()).to.eventually.have.length(1);
69+
});
70+
71+
it("should save successfully with only doc", function(){
72+
var nested = new TestMdlA({name: "Nested User 2", info: {foo: 'bar', some: 'string'}});
73+
74+
return task.save(nested).run();
75+
});
76+
77+
it("should have Nested User in " + TEST_COLLECTION_A, function(){
78+
return expect(TestMdlA.find({name: "Nested User 2", 'info.foo': 'bar'}).exec()).to.eventually.have.length(1);
79+
});
80+
81+
it(TEST_COLLECTION_A + " should have length 4", function(){
82+
return expect(TestMdlA.find().exec()).to.eventually.have.length(4);
83+
});
84+
});
85+
6086
describe("#update", function(){
6187
it("should update successfully", function(){
6288
return TestMdlB.findOne({name: "Brian Griffin"})
@@ -85,15 +111,33 @@ module.exports = describe("Task", function(){
85111
return expect(TestMdlB.find({name: "T-REX"}).exec()).to.eventually.have.length(1);
86112
});
87113

88-
it(TEST_COLLECTION_A + " should have length 2", function(){
89-
return expect(TestMdlA.find().exec()).to.eventually.have.length(2);
114+
it(TEST_COLLECTION_A + " should have length 4", function(){
115+
return expect(TestMdlA.find().exec()).to.eventually.have.length(4);
90116
});
91117

92118
it(TEST_COLLECTION_B + " should have length 2", function(){
93119
return expect(TestMdlB.find().exec()).to.eventually.have.length(2);
94120
});
95121
});
96122

123+
describe("#update $ token", function(){
124+
it("should update successfully with $gte", function(){
125+
return task.update(TestMdlB, {name: "Yo momma", age: {$gte: 38}}, {$inc: {age: 20}}).run();
126+
});
127+
128+
it("should have Yo momma in " + TEST_COLLECTION_B + " with age 58", function(){
129+
return expect(TestMdlB.find({name: "Yo momma", age: 58}).exec()).to.eventually.have.length(1);
130+
});
131+
132+
it("should update successfully with $inc", function(){
133+
return task.update(TestMdlB, {name: "Yo momma", age: {$in: [58, 59]}}, {$inc: {age: -20}}).run();
134+
});
135+
136+
it("should have Yo momma in " + TEST_COLLECTION_B + " with age 38", function(){
137+
return expect(TestMdlB.find({name: "Yo momma", age: 38}).exec()).to.eventually.have.length(1);
138+
});
139+
});
140+
97141
describe("#remove", function(){
98142
it("should remove successfully", function(){
99143
return TestMdlB.findOne({name: "Yo momma"})
@@ -122,8 +166,8 @@ module.exports = describe("Task", function(){
122166
return expect(TestMdlB.find({name: "T-REX"}).exec()).to.eventually.have.length(1);
123167
});
124168

125-
it(TEST_COLLECTION_A + " should have length 1", function(){
126-
return expect(TestMdlA.find().exec()).to.eventually.have.length(1);
169+
it(TEST_COLLECTION_A + " should have length 3", function(){
170+
return expect(TestMdlA.find().exec()).to.eventually.have.length(3);
127171
});
128172

129173
it(TEST_COLLECTION_B + " should have length 1", function(){
@@ -162,12 +206,12 @@ module.exports = describe("Task", function(){
162206
return expect(TestMdlB.find({name: "Brian Griffin"}).exec()).to.eventually.have.length(1);
163207
});
164208

165-
it(TEST_COLLECTION_A + " should have length 2", function(){
166-
return expect(TestMdlA.find().exec()).to.eventually.have.length(2);
209+
it(TEST_COLLECTION_A + " should have length 4", function(){
210+
return expect(TestMdlA.find().exec()).to.eventually.have.length(4);
167211
});
168212

169213
it(TEST_COLLECTION_B + " should have length 2", function(){
170214
return expect(TestMdlB.find().exec()).to.eventually.have.length(2);
171215
});
172216
});
173-
});
217+
});

0 commit comments

Comments
 (0)