Im Frontend-Image fehlt der Backend-Ordner; describe.skipIf führt den Rumpf beim Sammeln trotzdem aus, das readFileSync dort brach den Build ab (ENOENT). Das Fixture wird jetzt im Test gelesen. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { existsSync, readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
INSPECTION_SCALE_DIRECTIONS,
|
|
INSPECTION_SCALE_LABELS,
|
|
type InspectionScaleField,
|
|
} from "./scales";
|
|
|
|
interface ScaleFixture {
|
|
field: string;
|
|
storedOne: string;
|
|
storedFive: string;
|
|
anchors: Record<string, number>;
|
|
}
|
|
|
|
// The one source both sides read: the backend prompt and this form.
|
|
const FIXTURE_PATH = path.resolve(
|
|
process.cwd(),
|
|
"../ApiCore-Backend/test/fixtures/voice/inspection-scales.json",
|
|
);
|
|
|
|
/** Which stored end is the good one - a fact about beekeeping, not derivable from the words. */
|
|
const GOOD_STORED_END: Record<InspectionScaleField, 1 | 5> = {
|
|
broodPattern: 5,
|
|
swarmMood: 1,
|
|
gentleness: 5,
|
|
combBehavior: 5,
|
|
};
|
|
|
|
// The frontend image builds without the backend folder: then there is nothing to compare.
|
|
// The callback of a skipped describe still runs while collecting, so the file
|
|
// is read lazily inside the tests.
|
|
const readFixture = (): ScaleFixture[] =>
|
|
JSON.parse(readFileSync(FIXTURE_PATH, "utf8")) as ScaleFixture[];
|
|
|
|
describe.skipIf(!existsSync(FIXTURE_PATH))("inspection scales", () => {
|
|
|
|
it("scale directions equal the shared fixture", () => {
|
|
const fixture = readFixture();
|
|
expect(Object.keys(INSPECTION_SCALE_DIRECTIONS).sort()).toEqual(
|
|
fixture.map((scale) => scale.field).sort(),
|
|
);
|
|
for (const scale of fixture) {
|
|
const field = scale.field as InspectionScaleField;
|
|
expect(INSPECTION_SCALE_LABELS[field], field).toEqual({
|
|
lowLabel: scale.storedOne,
|
|
highLabel: scale.storedFive,
|
|
});
|
|
expect(scale.anchors[scale.storedOne], field).toBe(1);
|
|
expect(scale.anchors[scale.storedFive], field).toBe(5);
|
|
expect(INSPECTION_SCALE_DIRECTIONS[field], field).toBe(
|
|
GOOD_STORED_END[field] === 5 ? "higher-is-better" : "lower-is-better",
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("inspection scales (without the fixture)", () => {
|
|
it("mirrors only the swarm mood, whose stored 1 is the calm end", () => {
|
|
const mirrored = Object.entries(INSPECTION_SCALE_DIRECTIONS)
|
|
.filter(([, direction]) => direction === "lower-is-better")
|
|
.map(([field]) => field);
|
|
expect(mirrored).toEqual(["swarmMood"]);
|
|
});
|
|
});
|