Skip to content

Commit 2faae5e

Browse files
committed
test: add coverage for issues referenced in #14119
1 parent 099e79a commit 2faae5e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/types/queries.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,47 @@ async function gh15526() {
726726
expectType<string | undefined | null>(u1.name);
727727
expectError(u1.age);
728728
}
729+
730+
async function gh14173() {
731+
const userSchema = new Schema({
732+
name: String,
733+
account: {
734+
amount: Number,
735+
owner: { type: String, default: () => 'OWNER' },
736+
taxIds: [Number]
737+
}
738+
});
739+
const User = model('User', userSchema);
740+
741+
const { _id } = await User.create({
742+
name: 'test',
743+
account: {
744+
amount: 25,
745+
owner: 'test',
746+
taxIds: [42]
747+
}
748+
});
749+
750+
const doc = await User
751+
.findOne({ _id }, { name: 1, account: { amount: 1 } })
752+
.orFail();
753+
}
754+
755+
async function gh3230() {
756+
const Test = model(
757+
'Test',
758+
new Schema({ name: String, arr: [{ testRef: { type: 'ObjectId', ref: 'Test2' } }] })
759+
);
760+
761+
const schema = new Schema({ name: String });
762+
const Test2 = model('Test2', schema);
763+
const D = Test2.discriminator('D', new Schema({ prop: String }));
764+
765+
766+
await Test.deleteMany({});
767+
await Test2.deleteMany({});
768+
const { _id } = await D.create({ name: 'foo', prop: 'bar' });
769+
const test = await Test.create({ name: 'test', arr: [{ testRef: _id }] });
770+
771+
console.log(await Test.findById(test._id).populate('arr.testRef', { name: 1, prop: 1, _id: 0, __t: 0 }));
772+
}

0 commit comments

Comments
 (0)