import {
	ENUM_VALUES,
	policyActionLabel,
	policyReasonLabel,
	qclassName,
	rcodeName,
	routeKindLabel,
} from "./provenanceCopy";

/**
 * `tsc` proves the maps total over the union; this proves the union is the set
 * the server actually stores, and that no entry was left as its raw tag name.
 */
test("every stored enum value has a label of its own", () => {
	const labels = [
		...ENUM_VALUES.policyAction.map(policyActionLabel),
		...ENUM_VALUES.policyReason.map(policyReasonLabel),
		...ENUM_VALUES.routeKind.map(routeKindLabel),
	];
	for (const label of labels) {
		expect(label).not.toBe("");
		expect(label).not.toMatch(/_/);
	}
	expect(new Set(ENUM_VALUES.policyReason.map(policyReasonLabel)).size).toBe(ENUM_VALUES.policyReason.length);
});

test("response codes read by name where one exists, by number where none does", () => {
	expect(rcodeName(0)).toBe("NOERROR (0)");
	expect(rcodeName(3)).toBe("NXDOMAIN (3)");
	expect(rcodeName(16)).toBe("BADVERS (16)");
	// The column holds the twelve-bit extended code, most of which is unassigned.
	expect(rcodeName(3841)).toBe("RCODE 3841");
});

test("query classes read the same way", () => {
	expect(qclassName(1)).toBe("IN (1)");
	expect(qclassName(255)).toBe("ANY (255)");
	expect(qclassName(42)).toBe("CLASS 42");
});
