Skip to content

Commit

Permalink
test(map): add test coverage for queries
Browse files Browse the repository at this point in the history
Re: #681
  • Loading branch information
vkarpov15 committed Mar 30, 2018
1 parent a66c839 commit e753446
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/types.map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,44 @@ describe('Map', function() {
assert.ok(threw);
});
});

it('query casting', function() {
const TestSchema = new mongoose.Schema({
v: {
type: Map,
of: Number
}
});

const Test = db.model('MapQueryTest', TestSchema);

return co(function*() {
const docs = yield Test.create([
{ v: { n: 1 } },
{ v: { n: 2 } }
]);

let res = yield Test.find({ 'v.n': 1 });
assert.equal(res.length, 1);

res = yield Test.find({ v: { n: 2 } });
assert.equal(res.length, 1);

yield Test.updateOne({ _id: docs[1]._id }, { 'v.n': 3 });

res = yield Test.find({ v: { n: 3 } });
assert.equal(res.length, 1);

let threw = false;
try {
yield Test.updateOne({ _id: docs[1]._id }, { 'v.n': 'not a number' });
} catch (error) {
threw = true;
assert.equal(error.name, 'CastError');
}
assert.ok(threw);
res = yield Test.find({ v: { n: 3 } });
assert.equal(res.length, 1);
});
});
});

0 comments on commit e753446

Please sign in to comment.