Files
united-workforce/packages/util/__tests__/refs-field.test.ts
T
xingyue dbb7885ffd
CI / check (pull_request) Failing after 1m39s
chore: fix biome check errors (40 → 0)
- Auto-fix: import sorting, formatting (17 files)
- Unsafe auto-fix: unused vars, template literals (7 files)
- Manual: nursery/noConsole → suspicious/noConsole suppression
- Manual: suppress noExcessiveCognitiveComplexity for cmdThreadResume and parseWorkflowPayload
- Manual: remove unused destructured vars in current-role tests

Closes #48
2026-06-04 16:45:45 +08:00

41 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { mergeRefsWithContentHash, normalizeRefsField } from "../src/refs-field.js";
describe("mergeRefsWithContentHash", () => {
it("appends a new content hash", () => {
expect(mergeRefsWithContentHash(["a", "b"], "c")).toEqual(["a", "b", "c"]);
});
it("skips duplicate content hash", () => {
expect(mergeRefsWithContentHash(["a", "b"], "b")).toEqual(["a", "b"]);
});
it("preserves order", () => {
expect(mergeRefsWithContentHash(["x", "y"], "z")).toEqual(["x", "y", "z"]);
});
it("handles empty refs", () => {
expect(mergeRefsWithContentHash([], "a")).toEqual(["a"]);
});
});
describe("normalizeRefsField", () => {
it("returns empty array for non-array", () => {
expect(normalizeRefsField(null)).toEqual([]);
expect(normalizeRefsField(undefined)).toEqual([]);
expect(normalizeRefsField(42)).toEqual([]);
});
it("passes through string array", () => {
expect(normalizeRefsField(["a", "b"])).toEqual(["a", "b"]);
});
it("filters non-strings from mixed array", () => {
expect(normalizeRefsField(["a", 1, "b", null])).toEqual(["a", "b"]);
});
it("handles empty array", () => {
expect(normalizeRefsField([])).toEqual([]);
});
});