import { describe, expect, it } from "vitest";
import { isOrganizationTree, isUserPage } from "../directoryTypes";

const organization = {
  id: "1",
  orgCode: "ORG_ROOT",
  orgName: "机关",
  parentId: null,
  orgPath: "/机关",
  sortNo: 10,
  status: "ENABLED",
  children: [{
    id: "2",
    orgCode: "ORG_OPS",
    orgName: "作战部",
    parentId: "1",
    orgPath: "/机关/作战部",
    sortNo: 20,
    status: "ENABLED",
    children: [],
  }],
};

const user = {
  id: "3",
  username: "user",
  realName: "普通用户",
  organizationId: "2",
  organizationName: "作战部",
  roleCode: "USER",
  securityLevel: "SECRET",
  status: "ENABLED",
  allowedModules: ["DOCUMENT_BROWSER"],
};

describe("directory DTO contracts", () => {
  it("递归接受组织树字符串ID", () => {
    expect(isOrganizationTree([organization])).toBe(true);
  });

  it("拒绝组织number ID和未知状态", () => {
    expect(isOrganizationTree([{ ...organization, id: 1 }])).toBe(false);
    expect(isOrganizationTree([{ ...organization, status: "UNKNOWN" }])).toBe(false);
  });

  it("接受安全UserSummary分页且不需要敏感字段", () => {
    expect(isUserPage({ items: [user], page: 1, pageSize: 20, total: 1, totalPages: 1 })).toBe(true);
  });

  it("拒绝人员和organizationId的number ID", () => {
    expect(isUserPage({ items: [{ ...user, id: 3 }], page: 1, pageSize: 20, total: 1, totalPages: 1 })).toBe(false);
    expect(isUserPage({ items: [{ ...user, organizationId: 2 }], page: 1, pageSize: 20, total: 1, totalPages: 1 })).toBe(false);
  });
});

