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:
2026-09-20 11:10:59 -04:00
parent 1ab34f4561
commit 777de1f63f
2 changed files with 34 additions and 1 deletions
+4
View File
@@ -62,6 +62,10 @@ await isAvailable("likely-unregistered-thing-320485230458.com"); // => true
- Returns the registrable domain string, or `null` for IPs/invalid input; [options](https://github.com/remusao/tldts/blob/master/packages/tldts-core/src/options.ts) are forwarded to `tldts` (e.g., `allowPrivateDomains`). - Returns the registrable domain string, or `null` for IPs/invalid input; [options](https://github.com/remusao/tldts/blob/master/packages/tldts-core/src/options.ts) are forwarded to `tldts` (e.g., `allowPrivateDomains`).
- `isRegistered(domain, options?) => Promise<boolean>` - `isRegistered(domain, options?) => Promise<boolean>`
- `isAvailable(domain, options?) => Promise<boolean>` - `isAvailable(domain, options?) => Promise<boolean>`
- `finalizeContact(contact, redactedHint?) => Contact`
- Cleans a contact: drops placeholder values (recording them in `redactedFields`), sets `privacyService`, resolves `country`/`countryCode`, and sets `redacted`. Safe to re-run on an already-cleaned contact, e.g. to upgrade contacts stored by an older version.
- `isPrivacyContact(contact) => boolean`
- True when the contact's name/organization is a privacy service or was redacted.
### CLI ### CLI
+30 -1
View File
@@ -1,6 +1,6 @@
import { expect, test } from "vitest"; import { expect, test } from "vitest";
import { finalizeContact, redactionFields } from "./contacts"; import { finalizeContact, redactionFields } from "./contacts";
import { isPlaceholderValue } from "./privacy"; import { isPlaceholderValue, isPrivacyName } from "./privacy";
import * as api from "../index"; import * as api from "../index";
test("finalizeContact drops placeholder name/organization and records redactedFields", () => { 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.finalizeContact).toBe(finalizeContact);
expect(api.isPrivacyContact({ type: "registrant", privacyService: true })).toBe(true); 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);
});