Skip to content

Commit

Permalink
Add tests for ignoring fields that aren't populatable
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Macalinao <me@ian.pw>
  • Loading branch information
macalinao committed Aug 12, 2014
1 parent 025de86 commit a0295ad
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,41 @@ describe('Model', function() {
});
});

it('should synchronously ignore untransformable fields', function(done) {
User.transformPopulate('age', function(req, doc) {
doc.name = 'Tim';
});
User.applyTransforms(null, {
toObject: function() {
return {
age: 10
};
}
}, function(err, doc) {
expect(doc.age.name).to.be.undefined;
done();
});
});

it('should asynchronously ignore unpopulatable fields', function(done) {
User.transformPopulate('age', function(req, doc, next) {
async.times(1, function() {
doc.name = 'Tim';
next();
});
});
User.applyTransforms(null, {
toObject: function() {
return {
age: 10
};
}
}, function(err, doc) {
expect(doc.age.name).to.be.undefined;
done();
});
});

it('should not transform a non-existent field', function(done) {
User.transformPopulate('dne', function(req, doc) {
doc.asdf = 'asdf';
Expand Down

0 comments on commit a0295ad

Please sign in to comment.