mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-29 10:28:04 +03:00
add tests
This commit is contained in:
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "../../test-utils/close-connections";
|
||||
import ResetDBState from "../../test-utils/resets";
|
||||
import db from "./db";
|
||||
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
t.test("ID field autoprojection", async (t) => {
|
||||
const res = await db.scores.findOne();
|
||||
t.equal(res!._id, undefined);
|
||||
|
||||
// @ts-expect-error todo: #205 type properly
|
||||
const res2 = await db.scores.findOne({}, { projectID: true });
|
||||
t.not(res2!._id, undefined);
|
||||
|
||||
const res3 = await db.scores.findOne({}, { projection: { scoreID: 1 } });
|
||||
t.equal(res3!._id, undefined);
|
||||
|
||||
// @ts-expect-error todo: #205 type properly
|
||||
const res4 = await db.scores.findOne({}, { projection: { scoreID: 1 }, projectID: true });
|
||||
t.not(res4!._id, undefined);
|
||||
|
||||
const res5 = await db.scores.findOne({}, { projection: { scoreID: 0 } });
|
||||
t.equal(res5!._id, undefined);
|
||||
|
||||
// @ts-expect-error todo: #205 type properly
|
||||
const res6 = await db.scores.findOne({}, { projection: { scoreID: 0 }, projectID: true });
|
||||
t.not(res6!._id, undefined);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
Vendored
+3
-3
@@ -72,10 +72,10 @@ const RemoveIDMiddleware: TMiddleware =
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(args: any, method) => {
|
||||
if ((method === "find" || method === "findOne") && !args.options.projectID) {
|
||||
if (args.options.project) {
|
||||
args.options.project._id = 0;
|
||||
if (args.options.projection) {
|
||||
args.options.projection._id = 0;
|
||||
} else {
|
||||
args.options.project = { _id: 0 };
|
||||
args.options.projection = { _id: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user