AdithyaSK's picture
AdithyaSK HF Staff
Add files using upload-large-folder tool
ca30ad9 verified
Raw
History Blame Contribute Delete
5.15 kB
diff --git a/test/types/lean.test.ts b/test/types/lean.test.ts
index 745999d3a..05f34d96f 100644
--- a/test/types/lean.test.ts
+++ b/test/types/lean.test.ts
@@ -1,4 +1,4 @@
-import { Schema, model, Types, InferSchemaType, FlattenMaps } from 'mongoose';
+import { Schema, model, Types, InferSchemaType, FlattenMaps, Require_id } from 'mongoose';
import { expectAssignable, expectError, expectType } from 'tsd';
function gh10345() {
@@ -206,3 +206,107 @@ async function gh13382() {
const res = await Test.updateOne({}, { name: 'bar' }).lean();
expectAssignable<{ matchedCount: number, modifiedCount: number }>(res);
}
+
+async function gh13702_findById_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findById('id', undefined, { lean: true });
+ const b = await UserModel.findById('id').lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+
+ const a2 = await UserModel.findById('id', null, { lean: true });
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a2);
+}
+
+async function gh13702_findById_no_lean_preserves_hydrated() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findById('id');
+ if (a) {
+
+ expectAssignable<Function>(a.save);
+ }
+}
+
+async function gh13702_findOne_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOne({}, undefined, { lean: true });
+ const b = await UserModel.findOne({}).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_find_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.find({}, undefined, { lean: true });
+ const b = await UserModel.find({}).lean();
+ expectType<typeof b>(a);
+ expectType<Array<FlattenMaps<User> & { _id: Types.ObjectId }>>(a);
+}
+
+async function gh13702_findOneAndDelete_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOneAndDelete({}, { lean: true });
+ const b = await UserModel.findOneAndDelete({}).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findOneAndUpdate_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOneAndUpdate({}, { name: 'x' }, { lean: true });
+ const b = await UserModel.findOneAndUpdate({}, { name: 'x' }).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findOneAndReplace_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findOneAndReplace({}, { name: 'x' }, { lean: true });
+ const b = await UserModel.findOneAndReplace({}, { name: 'x' }).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findByIdAndDelete_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findByIdAndDelete('id', { lean: true });
+ const b = await UserModel.findByIdAndDelete('id').lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findByIdAndRemove_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findByIdAndRemove('id', { lean: true });
+ const b = await UserModel.findByIdAndRemove('id').lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
+
+async function gh13702_findByIdAndUpdate_lean_option() {
+ interface User { name: string; }
+ const UserModel = model<User>('User', new Schema({ name: String }));
+
+ const a = await UserModel.findByIdAndUpdate('id', { name: 'x' }, { lean: true });
+ const b = await UserModel.findByIdAndUpdate('id', { name: 'x' }).lean();
+ expectType<typeof b>(a);
+ expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a);
+}
diff --git a/test_commands.json b/test_commands.json
new file mode 100644
index 000000000..8fcadc25d
--- /dev/null
+++ b/test_commands.json
@@ -0,0 +1,3 @@
+{
+ "test_commands": ["./node_modules/.bin/tsd"]
+}
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+set -uo pipefail
+cd /testbed
+rc=0
+./node_modules/.bin/tsd
+rc=$(( rc | $? ))
+exit $rc