mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fix repository's findOne to allow offset and sort – fixes module manager's config retrieval
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { mark, stripMark } from "../src/core/utils";
|
||||
import { ModuleManager } from "../src/modules/ModuleManager";
|
||||
import { entity, text } from "../src/data";
|
||||
import { ModuleManager, getDefaultConfig } from "../src/modules/ModuleManager";
|
||||
import { CURRENT_VERSION, TABLE_NAME } from "../src/modules/migrations";
|
||||
import { getDummyConnection } from "./helper";
|
||||
|
||||
@@ -29,7 +30,19 @@ describe("ModuleManager", async () => {
|
||||
const mm = new ModuleManager(c.dummyConnection);
|
||||
await mm.build();
|
||||
const version = mm.version();
|
||||
const json = mm.configs();
|
||||
const configs = mm.configs();
|
||||
const json = stripMark({
|
||||
...configs,
|
||||
data: {
|
||||
...configs.data,
|
||||
basepath: "/api/data2",
|
||||
entities: {
|
||||
test: entity("test", {
|
||||
content: text()
|
||||
}).toJSON()
|
||||
}
|
||||
}
|
||||
});
|
||||
//const { version, ...json } = mm.toJSON() as any;
|
||||
|
||||
const c2 = getDummyConnection();
|
||||
@@ -37,13 +50,48 @@ describe("ModuleManager", async () => {
|
||||
const mm2 = new ModuleManager(c2.dummyConnection, { initial: { version, ...json } });
|
||||
await mm2.syncConfigTable();
|
||||
await db
|
||||
.updateTable(TABLE_NAME)
|
||||
.set({ json: JSON.stringify(json), version: CURRENT_VERSION })
|
||||
.insertInto(TABLE_NAME)
|
||||
.values({ type: "config", json: JSON.stringify(json), version: CURRENT_VERSION })
|
||||
.execute();
|
||||
|
||||
await mm2.build();
|
||||
|
||||
expect(json).toEqual(mm2.configs());
|
||||
expect(json).toEqual(stripMark(mm2.configs()));
|
||||
});
|
||||
|
||||
test("s3.1: (fetch) config given, table exists, version matches", async () => {
|
||||
const configs = getDefaultConfig();
|
||||
const json = {
|
||||
...configs,
|
||||
data: {
|
||||
...configs.data,
|
||||
basepath: "/api/data2",
|
||||
entities: {
|
||||
test: entity("test", {
|
||||
content: text()
|
||||
}).toJSON()
|
||||
}
|
||||
}
|
||||
};
|
||||
//const { version, ...json } = mm.toJSON() as any;
|
||||
|
||||
const { dummyConnection } = getDummyConnection();
|
||||
const db = dummyConnection.kysely;
|
||||
const mm2 = new ModuleManager(dummyConnection);
|
||||
await mm2.syncConfigTable();
|
||||
// assume an initial version
|
||||
await db.insertInto(TABLE_NAME).values({ type: "config", json: null, version: 1 }).execute();
|
||||
await db
|
||||
.insertInto(TABLE_NAME)
|
||||
.values({ type: "config", json: JSON.stringify(json), version: CURRENT_VERSION })
|
||||
.execute();
|
||||
|
||||
await mm2.build();
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
test("s4: config given, table exists, version outdated, migrate", async () => {
|
||||
|
||||
Reference in New Issue
Block a user