Skip to content

Commit

Permalink
refactor(finance): deprecate maskedNumber for removal (#3201)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Nov 12, 2024
1 parent 9abaed1 commit cb4b77c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
23 changes: 20 additions & 3 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.3.0',
until: '10.0.0',
});

if (typeof options === 'number') {
options = { length: options };
}
Expand Down Expand Up @@ -952,7 +969,7 @@ export class FinanceModule extends ModuleBase {
*
* @example
* faker.finance.transactionDescription()
* // 'invoice transaction at Kilback - Durgan using card ending with ***(...4316) for UAH 783.82 in account ***16168663'
* // 'invoice transaction at Kilback - Durgan using card ending with ************4316 for UAH 783.82 in account ***16168663'
*
* @since 5.1.0
*/
Expand All @@ -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})/g, '*');
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 ************4719 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 ***************2758 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 *********6413 for JMD 262.02 in account ***52971361"`;

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

0 comments on commit cb4b77c

Please sign in to comment.