mirror of
https://github.com/jakejarvis/rdapper.git
synced 2026-09-23 00:15: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:
@@ -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`).
|
||||
- `isRegistered(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
|
||||
|
||||
|
||||
@@ -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