This commit is contained in:
dswbx
2025-06-21 17:05:27 +02:00
parent 42edce904f
commit 6e78a4c238
37 changed files with 215 additions and 125 deletions
+14 -10
View File
@@ -1,12 +1,12 @@
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
import { disableConsoleLog, enableConsoleLog, stripMark } from "core/utils";
import { disableConsoleLog, enableConsoleLog } from "core/utils";
import { Type } from "@sinclair/typebox";
import { Connection, entity, text } from "data";
import { Module } from "modules/Module";
import { type ConfigTable, getDefaultConfig, ModuleManager } from "modules/ModuleManager";
import { CURRENT_VERSION, TABLE_NAME } from "modules/migrations";
import { getDummyConnection } from "../helper";
import { diff } from "core/object/diff";
import { s, stripMark } from "core/object/schema";
import type { Static } from "@sinclair/typebox";
describe("ModuleManager", async () => {
@@ -92,7 +92,11 @@ describe("ModuleManager", async () => {
await mm2.build();
expect(stripMark(json)).toEqual(stripMark(mm2.configs()));
/* console.log({
json,
configs: mm2.configs(),
}); */
//expect(stripMark(json)).toEqual(stripMark(mm2.configs()));
expect(mm2.configs().data.entities?.test).toBeDefined();
expect(mm2.configs().data.entities?.test?.fields?.content).toBeDefined();
expect(mm2.get("data").toJSON().entities?.test?.fields?.content).toBeDefined();
@@ -257,10 +261,10 @@ describe("ModuleManager", async () => {
// @todo: add tests for migrations (check "backup" and new version)
describe("revert", async () => {
const failingModuleSchema = Type.Object({
value: Type.Optional(Type.Number()),
const failingModuleSchema = s.partialObject({
value: s.number(),
});
class FailingModule extends Module<typeof failingModuleSchema> {
class FailingModule extends Module<s.Static<typeof failingModuleSchema>> {
getSchema() {
return failingModuleSchema;
}
@@ -431,11 +435,11 @@ describe("ModuleManager", async () => {
});
describe("validate & revert", () => {
const schema = Type.Object({
value: Type.Array(Type.Number(), { default: [] }),
const schema = s.object({
value: s.array(s.number()),
});
type SampleSchema = Static<typeof schema>;
class Sample extends Module<typeof schema> {
type SampleSchema = s.Static<typeof schema>;
class Sample extends Module<SampleSchema> {
getSchema() {
return schema;
}