Skip to content

Commit

Permalink
chore: harden tests and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Wheale committed Jul 11, 2024
1 parent 5dfba6b commit cc85664
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('mongoose-lean-getters', function() {
assert.strictEqual(doc.field, '1337');
});

it('should should allow getters to transform return type', async function() {
it('should should allow array getters to non-arrays', async function() {
const userSchema = new mongoose.Schema({
emails: {
type: [String],
Expand All @@ -395,12 +395,14 @@ describe('mongoose-lean-getters', function() {
}
});
userSchema.plugin(mongooseLeanGetters);
const User = mongoose.model('transform-arrays', userSchema);
const User = mongoose.model('gh-37-transform-arrays', userSchema);

const variants = [
{ sourceVal: 'foo', expectedVal: 'foo' },
{ sourceVal: ['foo'], expectedVal: 'foo' },
{ sourceVal: ['foo', 'bar'], expectedVal: ['foo', 'bar'] },
{ sourceVal: [], expectedVal: undefined },
{ sourceVal: null, expectedVal: undefined },
{ sourceVal: undefined, expectedVal: undefined },
];

Expand All @@ -410,8 +412,9 @@ describe('mongoose-lean-getters', function() {
await user.save();

const foundUser = await User.findById(user._id).lean({ getters: true });
assert.deepStrictEqual(user.emails, expectedVal, `user did not have expected value { sourceVal: ${sourceVal}, expectedVal: ${expectedVal} }`);
assert.deepStrictEqual(foundUser.emails, expectedVal, `foundUser did not have expected value { sourceVal: ${sourceVal}, expectedVal: ${expectedVal}`);
const stringified = JSON.stringify({ sourceVal, expectedVal });
assert.deepStrictEqual(user.emails, expectedVal, `user did not have expected value ${stringified}`);
assert.deepStrictEqual(foundUser.emails, expectedVal, `foundUser did not have expected value ${stringified}`);
})
);
});
Expand Down

0 comments on commit cc85664

Please sign in to comment.