feat: centralize application framework primitives
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { createPluginRunner } from "@wrnexus/plugin";
|
||||
import { authzPlugin } from "../src/plugin.ts";
|
||||
|
||||
function runner() {
|
||||
return createPluginRunner(authzPlugin(), {
|
||||
root: process.cwd(),
|
||||
mode: "development",
|
||||
command: "dev",
|
||||
metadata: new Map(),
|
||||
warn() {},
|
||||
});
|
||||
}
|
||||
|
||||
test("authz plugin is inert until configured", async () => {
|
||||
const instance = runner();
|
||||
await instance.configure({});
|
||||
const contributions = await instance.contributions();
|
||||
expect(contributions.middleware).toEqual([]);
|
||||
expect(contributions.migrations).toEqual([]);
|
||||
});
|
||||
|
||||
test("database authz config contributes middleware and dialect migration", async () => {
|
||||
const instance = runner();
|
||||
const config: Record<string, unknown> = {
|
||||
db: { driver: "postgres", url: "postgres://example" },
|
||||
authz: {
|
||||
store: "database",
|
||||
middleware: true,
|
||||
migrations: true,
|
||||
defaultRoles: { signup: ["manager"] },
|
||||
},
|
||||
};
|
||||
await instance.configure(config);
|
||||
const contributions = await instance.contributions();
|
||||
expect(contributions.middleware).toHaveLength(1);
|
||||
expect(contributions.migrations).toHaveLength(1);
|
||||
expect(contributions.migrations[0]?.source).toContain("SERIAL PRIMARY KEY");
|
||||
expect(config.authz).toMatchObject({ strict: true });
|
||||
});
|
||||
|
||||
test("database authz config refuses a missing database", async () => {
|
||||
const instance = runner();
|
||||
await expect(instance.configure({ authz: { store: "database" } })).rejects.toThrow(
|
||||
"requires config.db",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user