import { describe, expect, it } from "vitest";
import {
  RESTORE_DESCRIPTIONS,
  RESTORE_ERROR_MESSAGES,
  deletedByLabel,
  toUtcIso,
} from "../recycleBinLabels";

describe("F8 labels and time", () => {
  it("本地时间转换为UTC Z且保持半开结束边界", () => {
    const input = "2026-08-01T00:00";
    expect(toUtcIso(input)).toBe(new Date(input).toISOString());
    expect(toUtcIso(input)).toMatch(/Z$/);
  });

  it("deletedBy不使用updatedBy补齐", () => {
    expect(deletedByLabel(null)).toBe("删除人信息不可用");
    expect(
      deletedByLabel({
        userId: "1",
        username: "admin",
        realName: "系统管理员",
        organizationName: "机关",
      }),
    ).toContain("系统管理员（admin）");
  });

  it("三类恢复说明严格区分关系行为", () => {
    expect(RESTORE_DESCRIPTIONS.MAIN).toContain("权限和附件挂载");
    expect(RESTORE_DESCRIPTIONS.SUB_PLAN).toContain("继承");
    expect(RESTORE_DESCRIPTIONS.ATTACHMENT).toContain("不会恢复历史挂载");
  });

  it("固定错误均有不泄露内部路径的用户提示", () => {
    for (const code of [
      "DATA_VERSION_CONFLICT",
      "FILE_NOT_FOUND",
      "FILE_INTEGRITY_MISMATCH",
      "RESTORE_FILE_CHANGED",
      "RESTORE_CATEGORY_INVALID",
      "RESTORE_PARENT_INVALID",
      "RESTORE_PERMISSION_INVALID",
      "RESTORE_RELATION_CONFLICT",
      "FILE_PATH_INVALID",
    ]) {
      expect(RESTORE_ERROR_MESSAGES[code]).toBeTruthy();
      expect(RESTORE_ERROR_MESSAGES[code]).not.toMatch(/original\/|mysql|SQL/i);
    }
  });
});

