Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(finance): maskedNumber has incorrect defaults #2494

Merged
merged 12 commits into from
Nov 7, 2023
2 changes: 1 addition & 1 deletion src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class FinanceModule {
}

// set defaults
const { ellipsis, length = 4, parens } = options;
const { ellipsis = true, length = 4, parens = true } = options;

// create a template for length
let template = '';
Expand Down
54 changes: 27 additions & 27 deletions test/modules/__snapshots__/finance.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ exports[`finance > 42 > iban > with formatted option 1`] = `"GT03 9751 1086 7098

exports[`finance > 42 > litecoinAddress 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1b"`;

exports[`finance > 42 > mask > noArgs 1`] = `"3791"`;
exports[`finance > 42 > mask > noArgs 1`] = `"(...3791)"`;

exports[`finance > 42 > mask > with ellipsis 1`] = `"...3791"`;
exports[`finance > 42 > mask > with ellipsis 1`] = `"(...3791)"`;

exports[`finance > 42 > mask > with length 1`] = `"37917"`;
exports[`finance > 42 > mask > with length 1`] = `"(...37917)"`;

exports[`finance > 42 > mask > with length, parenthesis and ellipsis 1`] = `"(...37917)"`;

exports[`finance > 42 > mask > with parenthesis 1`] = `"(3791)"`;
exports[`finance > 42 > mask > with parenthesis 1`] = `"(...3791)"`;

exports[`finance > 42 > maskedNumber > noArgs 1`] = `"3791"`;
exports[`finance > 42 > maskedNumber > noArgs 1`] = `"(...3791)"`;

exports[`finance > 42 > maskedNumber > with length 1`] = `"37917"`;
exports[`finance > 42 > maskedNumber > with length 1`] = `"(...37917)"`;

exports[`finance > 42 > maskedNumber > with length and parenthesis option 1`] = `"37917"`;
exports[`finance > 42 > maskedNumber > with length and parenthesis option 1`] = `"...37917"`;

exports[`finance > 42 > maskedNumber > with length option 1`] = `"37917"`;
exports[`finance > 42 > maskedNumber > with length option 1`] = `"(...37917)"`;

exports[`finance > 42 > maskedNumber > with length, parenthesis and ellipsis option 1`] = `"...37917"`;

Expand All @@ -106,7 +106,7 @@ exports[`finance > 42 > pin > with length option 1`] = `"3791775514"`;

exports[`finance > 42 > routingNumber 1`] = `"379177554"`;

exports[`finance > 42 > transactionDescription 1`] = `"invoice transaction at Wiegand, Deckow and Reynolds using card ending with ***8361 for RSD 374.54 in account ***55141004"`;
exports[`finance > 42 > transactionDescription 1`] = `"invoice transaction at Wiegand, Deckow and Reynolds using card ending with ***(...8361) for RSD 374.54 in account ***55141004"`;

exports[`finance > 42 > transactionType 1`] = `"withdrawal"`;

Expand Down Expand Up @@ -188,23 +188,23 @@ exports[`finance > 1211 > iban > with formatted option 1`] = `"TN42 8201 6024 17

exports[`finance > 1211 > litecoinAddress 1`] = `"MTMe8Z3EaFdLqmaGKP1LEEJQVriSZRZds"`;

exports[`finance > 1211 > mask > noArgs 1`] = `"9487"`;
exports[`finance > 1211 > mask > noArgs 1`] = `"(...9487)"`;

exports[`finance > 1211 > mask > with ellipsis 1`] = `"...9487"`;
exports[`finance > 1211 > mask > with ellipsis 1`] = `"(...9487)"`;

exports[`finance > 1211 > mask > with length 1`] = `"94872"`;
exports[`finance > 1211 > mask > with length 1`] = `"(...94872)"`;

exports[`finance > 1211 > mask > with length, parenthesis and ellipsis 1`] = `"(...94872)"`;

exports[`finance > 1211 > mask > with parenthesis 1`] = `"(9487)"`;
exports[`finance > 1211 > mask > with parenthesis 1`] = `"(...9487)"`;

exports[`finance > 1211 > maskedNumber > noArgs 1`] = `"9487"`;
exports[`finance > 1211 > maskedNumber > noArgs 1`] = `"(...9487)"`;

exports[`finance > 1211 > maskedNumber > with length 1`] = `"94872"`;
exports[`finance > 1211 > maskedNumber > with length 1`] = `"(...94872)"`;

exports[`finance > 1211 > maskedNumber > with length and parenthesis option 1`] = `"94872"`;
exports[`finance > 1211 > maskedNumber > with length and parenthesis option 1`] = `"...94872"`;

exports[`finance > 1211 > maskedNumber > with length option 1`] = `"94872"`;
exports[`finance > 1211 > maskedNumber > with length option 1`] = `"(...94872)"`;

exports[`finance > 1211 > maskedNumber > with length, parenthesis and ellipsis option 1`] = `"...94872"`;

Expand All @@ -216,7 +216,7 @@ exports[`finance > 1211 > pin > with length option 1`] = `"9487219061"`;

exports[`finance > 1211 > routingNumber 1`] = `"948721904"`;

exports[`finance > 1211 > transactionDescription 1`] = `"deposit transaction at Trantow - Satterfield using card ending with ***4316 for SDG 928.52 in account ***19061627"`;
exports[`finance > 1211 > transactionDescription 1`] = `"deposit transaction at Trantow - Satterfield using card ending with ***(...4316) for SDG 928.52 in account ***19061627"`;

exports[`finance > 1211 > transactionType 1`] = `"invoice"`;

Expand Down Expand Up @@ -298,23 +298,23 @@ exports[`finance > 1337 > iban > with formatted option 1`] = `"FO56 1005 0250 09

exports[`finance > 1337 > litecoinAddress 1`] = `"Madhxs2jewAgkYgJi7No6Cn8JZar"`;

exports[`finance > 1337 > mask > noArgs 1`] = `"2512"`;
exports[`finance > 1337 > mask > noArgs 1`] = `"(...2512)"`;

exports[`finance > 1337 > mask > with ellipsis 1`] = `"...2512"`;
exports[`finance > 1337 > mask > with ellipsis 1`] = `"(...2512)"`;

exports[`finance > 1337 > mask > with length 1`] = `"25122"`;
exports[`finance > 1337 > mask > with length 1`] = `"(...25122)"`;

exports[`finance > 1337 > mask > with length, parenthesis and ellipsis 1`] = `"(...25122)"`;

exports[`finance > 1337 > mask > with parenthesis 1`] = `"(2512)"`;
exports[`finance > 1337 > mask > with parenthesis 1`] = `"(...2512)"`;

exports[`finance > 1337 > maskedNumber > noArgs 1`] = `"2512"`;
exports[`finance > 1337 > maskedNumber > noArgs 1`] = `"(...2512)"`;

exports[`finance > 1337 > maskedNumber > with length 1`] = `"25122"`;
exports[`finance > 1337 > maskedNumber > with length 1`] = `"(...25122)"`;

exports[`finance > 1337 > maskedNumber > with length and parenthesis option 1`] = `"25122"`;
exports[`finance > 1337 > maskedNumber > with length and parenthesis option 1`] = `"...25122"`;

exports[`finance > 1337 > maskedNumber > with length option 1`] = `"25122"`;
exports[`finance > 1337 > maskedNumber > with length option 1`] = `"(...25122)"`;

exports[`finance > 1337 > maskedNumber > with length, parenthesis and ellipsis option 1`] = `"...25122"`;

Expand All @@ -326,6 +326,6 @@ exports[`finance > 1337 > pin > with length option 1`] = `"2512254032"`;

exports[`finance > 1337 > routingNumber 1`] = `"251225401"`;

exports[`finance > 1337 > transactionDescription 1`] = `"withdrawal transaction at Cronin - Effertz using card ending with ***3927 for GIP 262.02 in account ***54032552"`;
exports[`finance > 1337 > transactionDescription 1`] = `"withdrawal transaction at Cronin - Effertz using card ending with ***(...3927) for GIP 262.02 in account ***54032552"`;

exports[`finance > 1337 > transactionType 1`] = `"withdrawal"`;
6 changes: 6 additions & 0 deletions test/modules/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ describe('finance', () => {
});

describe('maskedNumber()', () => {
it('should return contain parenthesis, ellipsis and have a length by default', () => {
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
const actual = faker.finance.maskedNumber();

expect(actual).toMatch(/\(\.{3}\d{4}\)/);
});

it('should set a default length', () => {
const expected = 4; // default account mask length
const mask = faker.finance.maskedNumber({
Expand Down