/**
* `isVisibleFacilitySection()` / `FACILITY_SECTION_VISIBLE_WHERE` の期待値表(指示書BB U1・D1・D-182)。
*
* | 施設の deleted_at | 清掃エリアの deleted_at | 見えるか |
* |---|---|---|
* | NULL | NULL | 見える |
* | 過去の日時 | NULL | 見えない |
* | NULL | 過去の日時 | 見えない |
* | 過去の日時 | 過去の日時 | 見えない |
* | ★未来の日時★ | NULL / NULL | 未来の日時 | ★見えない★(NULL か否かだけで決める) |
*
* ★`isVisibleErrorRow()` / `ERROR_ROW_VISIBLE_WHERE`(D-180)はこの2つに委ねる(名前だけ残す)★
*/
import { describe, expect, it } from "vitest";
import { ERROR_ROW_VISIBLE_WHERE, isVisibleErrorRow } from "@/lib/db/error-report-mapping";
import { FACILITY_SECTION_VISIBLE_WHERE, isVisibleFacilitySection } from "@/lib/db/visibility";
import { toDbJst } from "@/lib/format/date";
const DELETED = toDbJst(new Date("2026-10-01T10:00:00+09:00"));
const FUTURE = toDbJst(new Date("2099-01-01T00:00:00+09:00"));
describe("isVisibleFacilitySection(指示書BB U1)", () => {
it.each([
["施設・清掃エリアとも生きている", null, null, true],
["施設だけ削除済み", DELETED, null, false],
["清掃エリアだけ削除済み", null, DELETED, false],
["両方とも削除済み", DELETED, DELETED, false],
["★施設が未来の日時でも削除済み(NULL か否かだけ)★", FUTURE, null, false],
["★清掃エリアが未来の日時でも削除済み★", null, FUTURE, false],
] as const)("%s → %s", (_label, facilityDeleted, sectionDeleted, expected) => {
const row = { facility: { deleted_at: facilityDeleted }, section: { deleted_at: sectionDeleted } };
expect(isVisibleFacilitySection(row)).toBe(expected);
// ★`isVisibleErrorRow()` は同じ規則(委ねている)★
expect(isVisibleErrorRow(row)).toBe(expected);
});
});
describe("FACILITY_SECTION_VISIBLE_WHERE(SQL 側の写し)", () => {
it("施設・清掃エリアの deleted_at が NULL", () => {
expect(FACILITY_SECTION_VISIBLE_WHERE).toEqual({
facility: { deleted_at: null },
section: { deleted_at: null },
});
});
it("★`ERROR_ROW_VISIBLE_WHERE` は同じオブジェクト(規則は1か所)★", () => {
expect(ERROR_ROW_VISIBLE_WHERE).toBe(FACILITY_SECTION_VISIBLE_WHERE);
});
});