cd78f72f33
Complete rename of all technical identifiers across the codebase: Package names (11 packages): - @planarchy/* → @capakraken/* in all package.json, tsconfig, imports Import statements: 277 files, 548 occurrences replaced Database & Docker: - PostgreSQL user/db: planarchy → capakraken - Docker volumes: planarchy_pgdata → capakraken_pgdata - Connection strings updated in docker-compose, .env, CI CI/CD: - GitHub Actions workflow: all filter commands updated - Test database credentials updated Infrastructure: - Redis channel: planarchy:sse → capakraken:sse - Logger service name: planarchy-api → capakraken-api - Anonymization seed updated - Start/stop/restart scripts updated Test data: - Seed emails: @planarchy.dev → @capakraken.dev - E2E test credentials: all 11 spec files updated - Email defaults: @planarchy.app → @capakraken.app - localStorage keys: planarchy_* → capakraken_* Documentation: 30+ .md files updated Verification: - pnpm install: workspace resolution works - TypeScript: only pre-existing TS2589 (no new errors) - Engine: 310/310 tests pass - Staffing: 37/37 tests pass Co-Authored-By: claude-flow <ruv@ruv.net>
102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
import { BlueprintTarget, FieldType, type BlueprintFieldDefinition } from "@capakraken/shared";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { assertBlueprintDynamicFields } from "../router/blueprint-validation.js";
|
|
|
|
function createDbMock(result: { fieldDefs: unknown; target: BlueprintTarget } | null) {
|
|
return {
|
|
blueprint: {
|
|
findUnique: vi.fn().mockResolvedValue(result),
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("assertBlueprintDynamicFields", () => {
|
|
it("returns early when no blueprint is set", async () => {
|
|
const db = createDbMock(null);
|
|
|
|
await expect(
|
|
assertBlueprintDynamicFields({
|
|
db,
|
|
blueprintId: undefined,
|
|
dynamicFields: {},
|
|
target: BlueprintTarget.PROJECT,
|
|
}),
|
|
).resolves.toBeUndefined();
|
|
|
|
expect(db.blueprint.findUnique).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects a missing blueprint", async () => {
|
|
const db = createDbMock(null);
|
|
|
|
await expect(
|
|
assertBlueprintDynamicFields({
|
|
db,
|
|
blueprintId: "bp_missing",
|
|
dynamicFields: {},
|
|
target: BlueprintTarget.PROJECT,
|
|
}),
|
|
).rejects.toMatchObject({ code: "NOT_FOUND" } satisfies Partial<TRPCError>);
|
|
});
|
|
|
|
it("rejects a blueprint with the wrong target", async () => {
|
|
const db = createDbMock({ fieldDefs: [], target: BlueprintTarget.RESOURCE });
|
|
|
|
await expect(
|
|
assertBlueprintDynamicFields({
|
|
db,
|
|
blueprintId: "bp_resource",
|
|
dynamicFields: {},
|
|
target: BlueprintTarget.PROJECT,
|
|
}),
|
|
).rejects.toMatchObject({ code: "BAD_REQUEST" } satisfies Partial<TRPCError>);
|
|
});
|
|
|
|
it("rejects invalid dynamic field values", async () => {
|
|
const fieldDefs: BlueprintFieldDefinition[] = [
|
|
{
|
|
id: "cost-center",
|
|
key: "costCenter",
|
|
label: "Cost Center",
|
|
order: 0,
|
|
type: FieldType.NUMBER,
|
|
required: true,
|
|
},
|
|
];
|
|
const db = createDbMock({ fieldDefs, target: BlueprintTarget.PROJECT });
|
|
|
|
await expect(
|
|
assertBlueprintDynamicFields({
|
|
db,
|
|
blueprintId: "bp_project",
|
|
dynamicFields: { costCenter: "abc" },
|
|
target: BlueprintTarget.PROJECT,
|
|
}),
|
|
).rejects.toMatchObject({ code: "UNPROCESSABLE_CONTENT" } satisfies Partial<TRPCError>);
|
|
});
|
|
|
|
it("accepts valid dynamic field values", async () => {
|
|
const fieldDefs: BlueprintFieldDefinition[] = [
|
|
{
|
|
id: "cost-center",
|
|
key: "costCenter",
|
|
label: "Cost Center",
|
|
order: 0,
|
|
type: FieldType.NUMBER,
|
|
required: true,
|
|
},
|
|
];
|
|
const db = createDbMock({ fieldDefs, target: BlueprintTarget.PROJECT });
|
|
|
|
await expect(
|
|
assertBlueprintDynamicFields({
|
|
db,
|
|
blueprintId: "bp_project",
|
|
dynamicFields: { costCenter: 42 },
|
|
target: BlueprintTarget.PROJECT,
|
|
}),
|
|
).resolves.toBeUndefined();
|
|
});
|
|
});
|