Fix GenerateTestPAN: random fills, suppress cardType when unknown

This commit is contained in:
Jacob Marks 2026-05-17 13:33:28 -04:00
parent c405326f03
commit 0aadfb94e3
2 changed files with 11 additions and 15 deletions

View File

@ -220,11 +220,11 @@ function parsePan(pan) {
return { return {
pan: normalized, pan: normalized,
network: brand || "Unknown", network: brand || "Unknown",
cardType: typeHint ? typeHint.likelyType : "Unknown", ...(typeHint && typeHint.confidence !== "low" ? {
cardTypeConfidence: typeHint ? typeHint.confidence : "low", cardType: typeHint.likelyType,
cardTypeNote: typeHint ? cardTypeConfidence: typeHint.confidence,
typeHint.note : cardTypeNote: typeHint.note,
"Card type cannot be determined — the PAN did not match a known network range.", } : {}),
majorIndustryIdentifier: mii, majorIndustryIdentifier: mii,
majorIndustryIdentifierDescription: MII_DESCRIPTIONS[mii] || "Unknown", majorIndustryIdentifierDescription: MII_DESCRIPTIONS[mii] || "Unknown",
issuerIdentificationNumber: normalized.substring(0, Math.min(8, normalized.length)), issuerIdentificationNumber: normalized.substring(0, Math.min(8, normalized.length)),
@ -250,18 +250,17 @@ function finalizePan(body) {
} }
/** /**
* Generates a numeric filler string. * Generates random filler digits.
* *
* @param {number} length * @param {number} length
* @returns {string} * @returns {string}
*/ */
function fillerDigits(length) { function fillerDigits(length) {
const seed = "12345678901234567890"; return Array.from({ length }, () => Math.floor(Math.random() * 10)).join("");
return seed.repeat(Math.ceil(length / seed.length)).substring(0, length);
} }
/** /**
* Generates a deterministic brand-valid PAN. * Generates a random brand-valid PAN.
* *
* @param {string} brand * @param {string} brand
* @param {number} requestedLength * @param {number} requestedLength

View File

@ -401,9 +401,6 @@ TestRegister.addTests([
pan: "4024140000000131", pan: "4024140000000131",
source: "Public Visa test PAN published in Mastercard AVS scenario documentation.", source: "Public Visa test PAN published in Mastercard AVS scenario documentation.",
network: "Visa", network: "Visa",
cardType: "Unknown",
cardTypeConfidence: "low",
cardTypeNote: "Visa issues credit, debit, and prepaid cards. The product type is determined by the issuer BIN, not the PAN prefix — a BIN database lookup is required.",
majorIndustryIdentifier: "4", majorIndustryIdentifier: "4",
majorIndustryIdentifierDescription: "Banking and financial (Visa)", majorIndustryIdentifierDescription: "Banking and financial (Visa)",
issuerIdentificationNumber: "40241400", issuerIdentificationNumber: "40241400",
@ -424,13 +421,13 @@ TestRegister.addTests([
] ]
}, },
{ {
name: "Generate Test PAN: American Express generated sample", name: "Generate Test PAN: American Express curated sample",
input: "", input: "",
expectedOutput: "371234567890120", expectedOutput: "371449635398431",
recipeConfig: [ recipeConfig: [
{ {
op: "Generate Test PAN", op: "Generate Test PAN",
args: ["American Express", "Generated valid PAN", 15, false] args: ["American Express", "Curated sample", 15, false]
} }
] ]
}, },