import { describe, expect, it } from "vitest";
import {
connectionStatusFromControlStatus,
controlErrorStatusFromResolutionStatus,
controlStatusFromConnectionStatus,
resolutionStatusFromControlErrorStatus,
} from "@/lib/db/ds-status";
// 期待値表(D-065 Q1-2 / Q1-3。docs/decisions.md:483-484)
describe("connectionStatusFromControlStatus", () => {
it.each([
[0, "ok"],
[1, "error"],
] as const)("controls.status=%i → %s", (input, expected) => {
expect(connectionStatusFromControlStatus(input)).toBe(expected);
});
it("0/1以外は例外を投げる(黙って握りつぶさない)", () => {
expect(() => connectionStatusFromControlStatus(2)).toThrow();
expect(() => connectionStatusFromControlStatus(-1)).toThrow();
});
});
describe("controlStatusFromConnectionStatus", () => {
it.each([
["ok", 0],
["error", 1],
] as const)("connection_status=%s → %i(seedの逆変換)", (input, expected) => {
expect(controlStatusFromConnectionStatus(input)).toBe(expected);
});
});
describe("resolutionStatusFromControlErrorStatus", () => {
it.each([
[0, "pending"],
[1, "in_progress"],
[2, "done"],
] as const)("control_error_histories.status=%i → %s", (input, expected) => {
expect(resolutionStatusFromControlErrorStatus(input)).toBe(expected);
});
it("0/1/2以外は例外を投げる(黙って握りつぶさない)", () => {
expect(() => resolutionStatusFromControlErrorStatus(3)).toThrow();
expect(() => resolutionStatusFromControlErrorStatus(-1)).toThrow();
});
});
describe("controlErrorStatusFromResolutionStatus", () => {
it.each([
["pending", 0],
["in_progress", 1],
["done", 2],
] as const)("resolution_status=%s → %i(seedの逆変換)", (input, expected) => {
expect(controlErrorStatusFromResolutionStatus(input)).toBe(expected);
});
});
describe("往復(正変換 → 逆変換が元に戻ること)", () => {
it.each([0, 1] as const)("controls.status=%i", (status) => {
expect(
controlStatusFromConnectionStatus(connectionStatusFromControlStatus(status))
).toBe(status);
});
it.each([0, 1, 2] as const)("control_error_histories.status=%i", (status) => {
expect(
controlErrorStatusFromResolutionStatus(resolutionStatusFromControlErrorStatus(status))
).toBe(status);
});
});