Files
ThothII/backend/test/catalog-synthetic-sample-value.test.ts
T

30 lines
1.2 KiB
TypeScript

import { expect, test } from "vitest";
import { syntheticSampleValue } from "../src/catalog/synthetic-sample-value.js";
test.each([
["text[]", "tags", 1, "{tags_001,tags_002}"],
["json", "payload", 2, '{"example":"payload_002","sequence":2}'],
["jsonb", "attributes", 3, '{"example":"attributes_003","sequence":3}'],
["inet", "client_ip", 4, "192.0.2.4"],
["cidr", "network", 5, "192.0.2.0/24"],
["time without time zone", "opening_time", 6, "10:30:06"],
["interval", "duration", 7, "7 days 07:00:00"],
["bytea", "digest", 8, "\\x00000008"],
] as const)(
"creates a deterministic PostgreSQL-shaped value for %s",
(dataType, name, index, expected) => {
const column = { name, dataType };
expect(syntheticSampleValue(column, index)).toBe(expected);
expect(syntheticSampleValue(column, index)).toBe(expected);
},
);
test("uses the PostgreSQL type before birth-related name hints", () => {
expect(syntheticSampleValue({ name: "birth_year", dataType: "integer" }, 2)).toBe(1002);
expect(syntheticSampleValue({ name: "birth_date", dataType: "date" }, 2))
.toBe("1982-01-02");
expect(syntheticSampleValue({ name: "birth_recorded_at", dataType: "timestamp" }, 2))
.toBe("2024-01-02T10:30:00.000Z");
});