mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
Reworked `ensureEntity` to replace entities while maintaining their configuration and allowing type adjustments. Updated tests to verify type persistence and synchronization of entity properties.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { beforeEach, describe, expect, it } from "bun:test";
|
|
|
|
import { Hono } from "hono";
|
|
import { Guard } from "../../src/auth";
|
|
import { EventManager } from "../../src/core/events";
|
|
import { Default, stripMark } from "../../src/core/utils";
|
|
import { EntityManager } from "../../src/data";
|
|
import { Module, type ModuleBuildContext } from "../../src/modules/Module";
|
|
import { getDummyConnection } from "../helper";
|
|
|
|
export function makeCtx(overrides?: Partial<ModuleBuildContext>): ModuleBuildContext {
|
|
const { dummyConnection } = getDummyConnection();
|
|
return {
|
|
connection: dummyConnection,
|
|
server: new Hono(),
|
|
em: new EntityManager([], dummyConnection),
|
|
emgr: new EventManager(),
|
|
guard: new Guard(),
|
|
flags: Module.ctx_flags,
|
|
...overrides
|
|
};
|
|
}
|
|
|
|
export function moduleTestSuite(module: { new (): Module }) {
|
|
let ctx: ModuleBuildContext;
|
|
|
|
beforeEach(() => {
|
|
ctx = makeCtx();
|
|
});
|
|
|
|
describe("Module Tests", () => {
|
|
it("should build without exceptions", async () => {
|
|
const m = new module();
|
|
await m.setContext(ctx).build();
|
|
expect(m.toJSON()).toBeDefined();
|
|
});
|
|
|
|
it("uses the default config", async () => {
|
|
const m = new module();
|
|
await m.setContext(ctx).build();
|
|
expect(stripMark(m.toJSON())).toEqual(Default(m.getSchema(), {}));
|
|
});
|
|
});
|
|
}
|