47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { test, expect } from "bun:test";
|
|
import { scaffold, scaffoldResource } from "../src/generate.ts";
|
|
|
|
test("scaffold page: kebab file, PascalCase page name", () => {
|
|
const f = scaffold("page", "about-us");
|
|
expect(f.path).toBe("pages/about-us.wrn");
|
|
expect(f.content).toContain("page AboutUs {");
|
|
expect(f.content).toContain('layout = "public"');
|
|
});
|
|
|
|
test("scaffold component: props + class", () => {
|
|
const f = scaffold("component", "user-card");
|
|
expect(f.path).toBe("components/user-card.wrn");
|
|
expect(f.content).toContain("component UserCard {");
|
|
expect(f.content).toContain('class="wrn-user-card"');
|
|
});
|
|
|
|
test("scaffold api: nested path keeps directories, exports GET", () => {
|
|
const f = scaffold("api", "users/list");
|
|
expect(f.path).toBe("api/users/list.ts");
|
|
expect(f.content).toContain("export async function GET");
|
|
});
|
|
|
|
test("scaffold schema: validation object", () => {
|
|
const f = scaffold("schema", "signup");
|
|
expect(f.path).toBe("schemas/signup.ts");
|
|
expect(f.content).toContain('import { v } from "@wrnexus/validation"');
|
|
expect(f.content).toContain("export default v.object(");
|
|
});
|
|
|
|
test("scaffold strips extensions from the given name", () => {
|
|
expect(scaffold("page", "home.wrn").path).toBe("pages/home.wrn");
|
|
expect(scaffold("api", "ping.ts").path).toBe("api/ping.ts");
|
|
});
|
|
|
|
test("resource scaffold emits schema, handlers, routes and a page", () => {
|
|
const files = scaffoldResource("templates");
|
|
expect(files.map((file) => file.path)).toEqual([
|
|
"schemas/template.ts",
|
|
"resources/templates.ts",
|
|
"api/templates.ts",
|
|
"api/templates/[id].ts",
|
|
"pages/templates.wrn",
|
|
]);
|
|
expect(files[1]?.content).toContain("defineResource");
|
|
});
|