mirror of
https://gitee.com/pnoker/iot-dc3.git
synced 2026-11-01 02:31:46 +08:00
- migrate auth, manager, data, and agentic persistence to R2DBC - hard cut pagination, facade, gateway, web, and CLI contracts - remove legacy database and TSDB adapters and document validation gates BREAKING CHANGE: platform persistence now requires PostgreSQL 18 with TimescaleDB and the new reactive API contracts.
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { formatOutput, detectFormat } from "../src/utils/format";
|
|
|
|
describe("format utils", () => {
|
|
it("formatOutput json should stringify", () => {
|
|
const result = formatOutput({ ok: true, data: "test" }, "json");
|
|
const parsed = JSON.parse(result);
|
|
expect(parsed.ok).toBe(true);
|
|
expect(parsed.data).toBe("test");
|
|
});
|
|
|
|
it("formatOutput json should handle arrays", () => {
|
|
const result = formatOutput([{ id: 1, name: "a" }], "json");
|
|
const parsed = JSON.parse(result);
|
|
expect(parsed).toHaveLength(1);
|
|
expect(parsed[0].id).toBe(1);
|
|
});
|
|
|
|
it("formatOutput table should handle arrays", () => {
|
|
const result = formatOutput(
|
|
[
|
|
{ id: 1, name: "Device A" },
|
|
{ id: 2, name: "Device B" },
|
|
],
|
|
"table",
|
|
);
|
|
expect(result).toContain("Device A");
|
|
expect(result).toContain("Device B");
|
|
expect(result).toContain("id");
|
|
expect(result).toContain("name");
|
|
});
|
|
|
|
it("formatOutput table should handle empty array", () => {
|
|
const result = formatOutput([], "table");
|
|
expect(result).toBe("(empty)");
|
|
});
|
|
|
|
it("formatOutput table should handle flat object", () => {
|
|
const result = formatOutput(
|
|
{ gateway: "http://localhost:8000", tenant: "default" },
|
|
"table",
|
|
);
|
|
expect(result).toContain("gateway");
|
|
expect(result).toContain("default");
|
|
});
|
|
|
|
it("formatOutput should keep 204 results silent", () => {
|
|
expect(formatOutput(undefined, "json")).toBe("");
|
|
expect(formatOutput(undefined, "table")).toBe("");
|
|
expect(formatOutput(undefined, "yaml")).toBe("");
|
|
});
|
|
});
|