mirror of
https://github.com/jakejarvis/rdapper.git
synced 2026-09-23 01:25:31 -04:00
test: add coverage for whole-value placeholder matching, country redactionFields, and idempotent re-finalization
- Assert that bare "Not Available" / "No Data" phrases only match as a complete value and not substrings (e.g. `"Address not available in this region"` or `"No Data Corp"` are not placeholders); confirm `isPrivacyName` ignores them
- Assert `redactionFields("Registrant Country Code")` → `["country"]` and that a comma-separated multi-field name resolves all three constituent fields
- Assert that a contact with a placeholder country but a real `countryCode` has the country resolved from the code, records `"country"` in `redactedFields`, and produces identical output when passed through `finalizeContact` a second time
- Document `finalizeContact` and `isPrivacyContact` in README
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { finalizeContact, redactionFields } from "./contacts";
|
||||
import { isPlaceholderValue } from "./privacy";
|
||||
import { isPlaceholderValue, isPrivacyName } from "./privacy";
|
||||
import * as api from "../index";
|
||||
|
||||
test("finalizeContact drops placeholder name/organization and records redactedFields", () => {
|
||||
@@ -139,3 +139,32 @@ test("finalizeContact and isPrivacyContact are exported", () => {
|
||||
expect(api.finalizeContact).toBe(finalizeContact);
|
||||
expect(api.isPrivacyContact({ type: "registrant", privacyService: true })).toBe(true);
|
||||
});
|
||||
|
||||
test("bare 'not available' phrases are whole-value only", () => {
|
||||
expect(isPlaceholderValue("Address not available in this region")).toBe(false);
|
||||
expect(isPlaceholderValue("Not Available")).toBe(true);
|
||||
expect(isPrivacyName("Not Available")).toBe(false);
|
||||
expect(isPrivacyName("No Data Corp")).toBe(false);
|
||||
});
|
||||
|
||||
test("redactionFields handles country code and multi-field names", () => {
|
||||
expect(redactionFields("Registrant Country Code")).toEqual(["country"]);
|
||||
expect(redactionFields("Registrant Street, City, Country")).toEqual([
|
||||
"street",
|
||||
"city",
|
||||
"country",
|
||||
]);
|
||||
});
|
||||
|
||||
test("a dropped country keeps a separate countryCode, and survives re-finalizing", () => {
|
||||
const c = finalizeContact({ type: "registrant", country: "N/A", countryCode: "US" });
|
||||
expect(c.countryCode).toBe("US");
|
||||
expect(c.country).toBe("United States");
|
||||
expect(c.redactedFields).toEqual(["country"]);
|
||||
expect(c.redacted).toBe(true);
|
||||
|
||||
const again = finalizeContact(structuredClone(c));
|
||||
expect(again.redactedFields).toEqual(["country"]);
|
||||
expect(again.redacted).toBe(true);
|
||||
expect(again).toEqual(c);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user