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

refactor(finance): deprecate maskedNumber for removal #3201

Merged
merged 10 commits into from
Nov 12, 2024
21 changes: 19 additions & 2 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FakerError } from '../../errors/faker-error';
import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';
import type { BitcoinAddressFamilyType, BitcoinNetworkType } from './bitcoin';
import {
Expand Down Expand Up @@ -202,6 +203,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber(3) // '(...342)'
*
* @since 8.0.0
*
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(length?: number): string;
/**
Expand All @@ -219,6 +222,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
*
* @since 8.0.0
*
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(options?: {
/**
Expand Down Expand Up @@ -256,6 +261,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
*
* @since 8.0.0
*
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(
optionsOrLength?:
Expand Down Expand Up @@ -297,6 +304,8 @@ export class FinanceModule extends ModuleBase {
* faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298'
*
* @since 8.0.0
*
* @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead.
*/
maskedNumber(
options:
Expand All @@ -322,6 +331,14 @@ export class FinanceModule extends ModuleBase {
ellipsis?: boolean;
} = {}
): string {
deprecated({
deprecated: 'faker.finance.maskedNumber()',
proposed:
"faker.finance.iban().replace(/(?<=.{4})\\w(?=.{2})/g, '*') or a similar approach",
since: '9.1.0',
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
until: '10.0.0',
});

if (typeof options === 'number') {
options = { length: options };
}
Expand Down Expand Up @@ -961,9 +978,9 @@ export class FinanceModule extends ModuleBase {
const company = this.faker.company.name();
const transactionType = this.transactionType();
const account = this.accountNumber();
const card = this.maskedNumber();
const card = this.creditCardNumber().replaceAll(/(?<=.{4}).(?=.{2})/g, '*');
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
const currency = this.currencyCode();

return `${transactionType} transaction at ${company} using card ending with ***${card} for ${currency} ${amount} in account ***${account}`;
return `${transactionType} transaction at ${company} using card ending with ${card} for ${currency} ${amount} in account ***${account}`;
}
}
6 changes: 3 additions & 3 deletions test/modules/__snapshots__/finance.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports[`finance > 42 > pin > with length option 1`] = `"3975110867"`;

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

exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Reynolds, Miller and Crist using card ending with ***(...1135) for KES 374.54 in account ***08670982"`;
exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Reynolds, Miller and Crist using card ending with 3015**********19 for LYD 374.54 in account ***08670982"`;

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

Expand Down Expand Up @@ -172,7 +172,7 @@ exports[`finance > 1211 > pin > with length option 1`] = `"9829667368"`;

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

exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at Fahey, Zieme and Osinski using card ending with ***(...8825) for CRC 928.52 in account ***73687684"`;
exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at Fahey, Zieme and Osinski using card ending with 4251*************58 for HNL 928.52 in account ***73687684"`;

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

Expand Down Expand Up @@ -260,6 +260,6 @@ exports[`finance > 1337 > pin > with length option 1`] = `"2124352971"`;

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

exports[`finance > 1337 > transactionDescription 1`] = `"invoice transaction at Gottlieb - Koelpin using card ending with ***(...9477) for HUF 262.02 in account ***52971361"`;
exports[`finance > 1337 > transactionDescription 1`] = `"invoice transaction at Gottlieb - Koelpin using card ending with 4773*******13 for JMD 262.02 in account ***52971361"`;
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

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

describe('maskedNumber()', () => {
it('should return contain parenthesis, ellipsis and have a length of 4 by default', () => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const actual = faker.finance.maskedNumber();

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

it('should set a default length', () => {
const expected = 4; // default account mask length
// eslint-disable-next-line @typescript-eslint/no-deprecated
const mask = faker.finance.maskedNumber({
parens: false,
ellipsis: false,
Expand All @@ -179,6 +181,7 @@ describe('finance', () => {
it('should set a specified length', () => {
const expected = faker.number.int({ min: 1, max: 20 });

// eslint-disable-next-line @typescript-eslint/no-deprecated
const mask = faker.finance.maskedNumber({
length: expected,
parens: false,
Expand Down