From c1ddd9192f2dab50b398595c90f1ea6c9f21de3b Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 9 Mar 2024 10:04:38 +0100 Subject: [PATCH 1/5] refactor(finance)!: remove v8 deprecated finance methods --- src/modules/finance/index.ts | 413 +++--------------- .../__snapshots__/finance.spec.ts.snap | 78 ---- test/modules/finance-iban.spec.ts | 35 +- test/modules/finance.spec.ts | 123 ++---- 4 files changed, 108 insertions(+), 541 deletions(-) diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 335bac97479..b78b6a3f18b 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -1,5 +1,4 @@ import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; import iban from './iban'; @@ -53,32 +52,6 @@ export function prettyPrintIban(iban: string): string { * For blockchain related methods, use: [`bitcoinAddress()`](https://fakerjs.dev/api/finance.html#bitcoinaddress), [`ethereumAddress()`](https://fakerjs.dev/api/finance.html#ethereumaddress) and [`litecoinAddress()`](https://fakerjs.dev/api/finance.html#litecoinaddress). */ export class FinanceModule extends ModuleBase { - /** - * Generates a random account number. - * - * @param length The length of the account number. Defaults to `8`. - * - * @see faker.finance.accountNumber(): For the replacement method. - * - * @example - * faker.finance.account() // 92842238 - * faker.finance.account(5) // 32564 - * - * @since 2.0.1 - * - * @deprecated Use `faker.finance.accountNumber` instead. - */ - account(length?: number): string { - deprecated({ - deprecated: 'faker.finance.account', - proposed: 'faker.finance.accountNumber', - since: '8.0', - until: '9.0', - }); - - return this.accountNumber(length); - } - /** * Generates a random account number. * @@ -213,35 +186,6 @@ export class FinanceModule extends ModuleBase { return `${routingNumber}${Math.ceil(sum / 10) * 10 - sum}`; } - /** - * Generates a random masked number. - * - * @param length The length of the unmasked number. Defaults to `4`. - * @param parens Whether to use surrounding parenthesis. Defaults to `true`. - * @param ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. - * - * @see faker.finance.maskedNumber(): For the replacement method. - * - * @example - * faker.finance.mask() // '(...9711)' - * faker.finance.mask(3) // '(...342)' - * faker.finance.mask(3, false) // '...236' - * faker.finance.mask(3, false, false) // '298' - * - * @since 2.0.1 - * - * @deprecated Use `faker.finance.maskedNumber` instead. - */ - mask(length?: number, parens?: boolean, ellipsis?: boolean): string { - deprecated({ - deprecated: 'faker.finance.mask', - proposed: 'faker.finance.maskedNumber', - since: '8.0', - until: '9.0', - }); - return this.maskedNumber({ length, parens, ellipsis }); - } - /** * Generates a random masked number. * @@ -410,207 +354,46 @@ export class FinanceModule extends ModuleBase { * * @since 2.0.1 */ - amount(options?: { - /** - * The lower bound for the amount. - * - * @default 0 - */ - min?: number; - /** - * The upper bound for the amount. - * - * @default 1000 - */ - max?: number; - /** - * The number of decimal places for the amount. - * - * @default 2 - */ - dec?: number; - /** - * The symbol used to prefix the amount. - * - * @default '' - */ - symbol?: string; - /** - * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. - * - * @default false - */ - autoFormat?: boolean; - }): string; - /** - * Generates a random amount between the given bounds (inclusive). - * - * @param min The lower bound for the amount. Defaults to `0`. - * @param max The upper bound for the amount. Defaults to `1000`. - * @param dec The number of decimal places for the amount. Defaults to `2`. - * @param symbol The symbol used to prefix the amount. Defaults to `''`. - * @param autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. - * - * @example - * faker.finance.amount() // '617.87' - * faker.finance.amount(5, 10) // '5.53' - * faker.finance.amount(5, 10, 0) // '8' - * faker.finance.amount(5, 10, 2, '$') // '$5.85' - * faker.finance.amount(5, 10, 5, '', true) // '9,75067' - * - * @since 2.0.1 - * - * @deprecated Use `faker.finance.amount({ min, max, dec, symbol, autoFormat })` instead. - */ amount( - min?: number, - max?: number, - dec?: number, - symbol?: string, - autoFormat?: boolean - ): string; - /** - * Generates a random amount between the given bounds (inclusive). - * - * @param options An options object. - * @param options.min The lower bound for the amount. Defaults to `0`. - * @param options.max The upper bound for the amount. Defaults to `1000`. - * @param options.dec The number of decimal places for the amount. Defaults to `2`. - * @param options.symbol The symbol used to prefix the amount. Defaults to `''`. - * @param options.autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. - * @param legacyMax The upper bound for the amount. Defaults to `1000`. - * @param legacyDec The number of decimal places for the amount. Defaults to `2`. - * @param legacySymbol The symbol used to prefix the amount. Defaults to `''`. - * @param legacyAutoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. Defaults to `false`. - * - * @example - * faker.finance.amount() // '617.87' - * faker.finance.amount({ min: 5, max: 10 }) // '5.53' - * faker.finance.amount({ min: 5, max: 10, dec: 0 }) // '8' - * faker.finance.amount({ min: 5, max: 10, dec: 2, symbol: '$' }) // '$5.85' - * faker.finance.amount({ min: 5, max: 10, dec: 5, symbol: '', autoFormat: true }) // '9,75067' - * - * @since 2.0.1 - */ - amount( - options?: - | number - | { - /** - * The lower bound for the amount. - * - * @default 0 - */ - min?: number; - /** - * The upper bound for the amount. - * - * @default 1000 - */ - max?: number; - /** - * The number of decimal places for the amount. - * - * @default 2 - */ - dec?: number; - /** - * The symbol used to prefix the amount. - * - * @default '' - */ - symbol?: string; - /** - * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. - * - * @default false - */ - autoFormat?: boolean; - }, - legacyMax?: number, - legacyDec?: number, - legacySymbol?: string, - legacyAutoFormat?: boolean - ): string; - /** - * Generates a random amount between the given bounds (inclusive). - * - * @param options An options object. - * @param options.min The lower bound for the amount. Defaults to `0`. - * @param options.max The upper bound for the amount. Defaults to `1000`. - * @param options.dec The number of decimal places for the amount. Defaults to `2`. - * @param options.symbol The symbol used to prefix the amount. Defaults to `''`. - * @param options.autoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. - * @param legacyMax The upper bound for the amount. Defaults to `1000`. - * @param legacyDec The number of decimal places for the amount. Defaults to `2`. - * @param legacySymbol The symbol used to prefix the amount. Defaults to `''`. - * @param legacyAutoFormat If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. Defaults to `false`. - * - * @example - * faker.finance.amount() // '617.87' - * faker.finance.amount({ min: 5, max: 10 }) // '5.53' - * faker.finance.amount({ min: 5, max: 10, dec: 0 }) // '8' - * faker.finance.amount({ min: 5, max: 10, dec: 2, symbol: '$' }) // '$5.85' - * faker.finance.amount({ min: 5, max: 10, dec: 5, symbol: '', autoFormat: true }) // '9,75067' - * - * @since 2.0.1 - */ - amount( - options: - | number - | { - /** - * The lower bound for the amount. - * - * @default 0 - */ - min?: number; - /** - * The upper bound for the amount. - * - * @default 1000 - */ - max?: number; - /** - * The number of decimal places for the amount. - * - * @default 2 - */ - dec?: number; - /** - * The symbol used to prefix the amount. - * - * @default '' - */ - symbol?: string; - /** - * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. - * - * @default false - */ - autoFormat?: boolean; - } = {}, - legacyMax: number = 1000, - legacyDec: number = 2, - legacySymbol: string = '', - legacyAutoFormat: boolean = false + options: { + /** + * The lower bound for the amount. + * + * @default 0 + */ + min?: number; + /** + * The upper bound for the amount. + * + * @default 1000 + */ + max?: number; + /** + * The number of decimal places for the amount. + * + * @default 2 + */ + dec?: number; + /** + * The symbol used to prefix the amount. + * + * @default '' + */ + symbol?: string; + /** + * If true this method will use `Number.toLocaleString()`. Otherwise it will use `Number.toFixed()`. + * + * @default false + */ + autoFormat?: boolean; + } = {} ): string { - if (typeof options === 'number') { - deprecated({ - deprecated: 'faker.finance.amount(min, max, dec, symbol, autoFormat)', - proposed: 'faker.finance.amount({ min, max, dec, symbol, autoFormat })', - since: '8.0', - until: '9.0', - }); - options = { min: options }; - } - const { - autoFormat = legacyAutoFormat, - dec = legacyDec, - max = legacyMax, + autoFormat = false, + dec = 2, + max = 1000, min = 0, - symbol = legacySymbol, + symbol = '', } = options; const randValue = this.faker.number.float({ @@ -1017,118 +800,22 @@ export class FinanceModule extends ModuleBase { * * @since 4.0.0 */ - iban(options?: { - /** - * Return a formatted version of the generated IBAN. - * - * @default false - */ - formatted?: boolean; - /** - * The country code from which you want to generate an IBAN, - * if none is provided a random country will be used. - */ - countryCode?: string; - }): string; - /** - * Generates a random iban. - * - * @param formatted Return a formatted version of the generated IBAN. Defaults to `false`. - * @param countryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. - * - * @throws Will throw an error if the passed country code is not supported. - * - * @example - * faker.finance.iban() // 'TR736918640040966092800056' - * faker.finance.iban(true) // 'FR20 8008 2330 8984 74S3 Z620 224' - * faker.finance.iban(true, 'DE') // 'DE84 1022 7075 0900 1170 01' - * - * @since 4.0.0 - * - * @deprecated Use `faker.finance.iban({ formatted, countryCode })` instead. - */ - iban(formatted?: boolean, countryCode?: string): string; - /** - * Generates a random iban. - * - * @param options An options object or whether the return value should be formatted. - * @param options.formatted Return a formatted version of the generated IBAN. Defaults to `false`. - * @param options.countryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. - * @param legacyCountryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. - * - * @throws Will throw an error if the passed country code is not supported. - * - * @example - * faker.finance.iban() // 'TR736918640040966092800056' - * faker.finance.iban({ formatted: true }) // 'FR20 8008 2330 8984 74S3 Z620 224' - * faker.finance.iban({ formatted: true, countryCode: 'DE' }) // 'DE84 1022 7075 0900 1170 01' - * - * @since 4.0.0 - */ iban( - options?: - | boolean - | { - /** - * Return a formatted version of the generated IBAN. - * - * @default false - */ - formatted?: boolean; - /** - * The country code from which you want to generate an IBAN, - * if none is provided a random country will be used. - */ - countryCode?: string; - }, - legacyCountryCode?: string - ): string; - /** - * Generates a random iban. - * - * @param options An options object or whether the return value should be formatted. - * @param options.formatted Return a formatted version of the generated IBAN. Defaults to `false`. - * @param options.countryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. - * @param legacyCountryCode The country code from which you want to generate an IBAN, if none is provided a random country will be used. - * - * @throws Will throw an error if the passed country code is not supported. - * - * @example - * faker.finance.iban() // 'TR736918640040966092800056' - * faker.finance.iban({ formatted: true }) // 'FR20 8008 2330 8984 74S3 Z620 224' - * faker.finance.iban({ formatted: true, countryCode: 'DE' }) // 'DE84 1022 7075 0900 1170 01' - * - * @since 4.0.0 - */ - iban( - options: - | boolean - | { - /** - * Return a formatted version of the generated IBAN. - * - * @default false - */ - formatted?: boolean; - /** - * The country code from which you want to generate an IBAN, - * if none is provided a random country will be used. - */ - countryCode?: string; - } = {}, - legacyCountryCode?: string + options: { + /** + * Return a formatted version of the generated IBAN. + * + * @default false + */ + formatted?: boolean; + /** + * The country code from which you want to generate an IBAN, + * if none is provided a random country will be used. + */ + countryCode?: string; + } = {} ): string { - if (typeof options === 'boolean') { - deprecated({ - deprecated: 'faker.finance.iban(formatted, countryCode)', - proposed: 'faker.finance.iban({ formatted, countryCode })', - since: '8.0', - until: '9.0', - }); - options = { formatted: options }; - } - - const { countryCode = legacyCountryCode, formatted = false } = options; + const { countryCode, formatted = false } = options; const ibanFormat = countryCode ? iban.formats.find((f) => f.country === countryCode) diff --git a/test/modules/__snapshots__/finance.spec.ts.snap b/test/modules/__snapshots__/finance.spec.ts.snap index 146db5d6290..30e1f66ae3d 100644 --- a/test/modules/__snapshots__/finance.spec.ts.snap +++ b/test/modules/__snapshots__/finance.spec.ts.snap @@ -1,9 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`finance > 42 > account > noArgs 1`] = `"39751108"`; - -exports[`finance > 42 > account > with length 1`] = `"3975110867"`; - exports[`finance > 42 > accountName 1`] = `"Money Market Account"`; exports[`finance > 42 > accountNumber > noArgs 1`] = `"39751108"`; @@ -14,18 +10,10 @@ exports[`finance > 42 > accountNumber > with length option 1`] = `"3975110867"`; exports[`finance > 42 > amount > noArgs 1`] = `"374.54"`; -exports[`finance > 42 > amount > with leagcy dec 1`] = `"374.54012"`; - -exports[`finance > 42 > amount > with leagcy max 1`] = `"18.73"`; - -exports[`finance > 42 > amount > with min 1`] = `"380.79"`; - exports[`finance > 42 > amount > with min and max option 1`] = `"24.98"`; exports[`finance > 42 > amount > with min option 1`] = `"380.79"`; -exports[`finance > 42 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$24.98160"`; - exports[`finance > 42 > amount > with min, max and dec option 1`] = `"24.98160"`; exports[`finance > 42 > amount > with min, max, dec and symbol option 1`] = `"#24.98160"`; @@ -68,26 +56,12 @@ exports[`finance > 42 > ethereumAddress 1`] = `"0x8ead331ddf0fc4446b96d368ab4bd1 exports[`finance > 42 > iban > noArgs 1`] = `"GT69T10P0V1346241560ZH610G35"`; -exports[`finance > 42 > iban > with formatted 1`] = `"GT69 T10P 0V13 4624 1560 ZH61 0G35"`; - -exports[`finance > 42 > iban > with formatted and countryCode 1`] = `"DE69 9500 1670 8002 5210 05"`; - exports[`finance > 42 > iban > with formatted and countryCode option 1`] = `"DE69 9500 1670 8002 5210 05"`; exports[`finance > 42 > iban > with formatted option 1`] = `"GT69 T10P 0V13 4624 1560 ZH61 0G35"`; exports[`finance > 42 > litecoinAddress 1`] = `"3JAaa4SAH2YQdbbiwrhB9hnsMcvA"`; -exports[`finance > 42 > mask > noArgs 1`] = `"(...3975)"`; - -exports[`finance > 42 > mask > with ellipsis 1`] = `"(...3975)"`; - -exports[`finance > 42 > mask > with length 1`] = `"(...39751)"`; - -exports[`finance > 42 > mask > with length, parenthesis and ellipsis 1`] = `"(...39751)"`; - -exports[`finance > 42 > mask > with parenthesis 1`] = `"(...3975)"`; - exports[`finance > 42 > maskedNumber > noArgs 1`] = `"(...3975)"`; exports[`finance > 42 > maskedNumber > with length 1`] = `"(...39751)"`; @@ -110,10 +84,6 @@ exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Re exports[`finance > 42 > transactionType 1`] = `"withdrawal"`; -exports[`finance > 1211 > account > noArgs 1`] = `"98296673"`; - -exports[`finance > 1211 > account > with length 1`] = `"9829667368"`; - exports[`finance > 1211 > accountName 1`] = `"Personal Loan Account"`; exports[`finance > 1211 > accountNumber > noArgs 1`] = `"98296673"`; @@ -124,18 +94,10 @@ exports[`finance > 1211 > accountNumber > with length option 1`] = `"9829667368" exports[`finance > 1211 > amount > noArgs 1`] = `"928.52"`; -exports[`finance > 1211 > amount > with leagcy dec 1`] = `"928.52016"`; - -exports[`finance > 1211 > amount > with leagcy max 1`] = `"46.43"`; - -exports[`finance > 1211 > amount > with min 1`] = `"929.24"`; - exports[`finance > 1211 > amount > with min and max option 1`] = `"47.15"`; exports[`finance > 1211 > amount > with min option 1`] = `"929.24"`; -exports[`finance > 1211 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$47.14081"`; - exports[`finance > 1211 > amount > with min, max and dec option 1`] = `"47.14081"`; exports[`finance > 1211 > amount > with min, max, dec and symbol option 1`] = `"#47.14081"`; @@ -178,26 +140,12 @@ exports[`finance > 1211 > ethereumAddress 1`] = `"0xed4fefa7fbaec9dc4c48fa8ebf46 exports[`finance > 1211 > iban > noArgs 1`] = `"TN8326736788219352058231"`; -exports[`finance > 1211 > iban > with formatted 1`] = `"TN83 2673 6788 2193 5205 8231"`; - -exports[`finance > 1211 > iban > with formatted and countryCode 1`] = `"DE13 8077 6768 8219 3520 53"`; - exports[`finance > 1211 > iban > with formatted and countryCode option 1`] = `"DE13 8077 6768 8219 3520 53"`; exports[`finance > 1211 > iban > with formatted option 1`] = `"TN83 2673 6788 2193 5205 8231"`; exports[`finance > 1211 > litecoinAddress 1`] = `"3eZEFLmGPLEQrSRdAcnZLoWwYeiHwmRog"`; -exports[`finance > 1211 > mask > noArgs 1`] = `"(...9829)"`; - -exports[`finance > 1211 > mask > with ellipsis 1`] = `"(...9829)"`; - -exports[`finance > 1211 > mask > with length 1`] = `"(...98296)"`; - -exports[`finance > 1211 > mask > with length, parenthesis and ellipsis 1`] = `"(...98296)"`; - -exports[`finance > 1211 > mask > with parenthesis 1`] = `"(...9829)"`; - exports[`finance > 1211 > maskedNumber > noArgs 1`] = `"(...9829)"`; exports[`finance > 1211 > maskedNumber > with length 1`] = `"(...98296)"`; @@ -220,10 +168,6 @@ exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at exports[`finance > 1211 > transactionType 1`] = `"invoice"`; -exports[`finance > 1337 > account > noArgs 1`] = `"21243529"`; - -exports[`finance > 1337 > account > with length 1`] = `"2124352971"`; - exports[`finance > 1337 > accountName 1`] = `"Money Market Account"`; exports[`finance > 1337 > accountNumber > noArgs 1`] = `"21243529"`; @@ -234,18 +178,10 @@ exports[`finance > 1337 > accountNumber > with length option 1`] = `"2124352971" exports[`finance > 1337 > amount > noArgs 1`] = `"262.02"`; -exports[`finance > 1337 > amount > with leagcy dec 1`] = `"262.02467"`; - -exports[`finance > 1337 > amount > with leagcy max 1`] = `"13.10"`; - -exports[`finance > 1337 > amount > with min 1`] = `"269.40"`; - exports[`finance > 1337 > amount > with min and max option 1`] = `"20.48"`; exports[`finance > 1337 > amount > with min option 1`] = `"269.40"`; -exports[`finance > 1337 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$20.48098"`; - exports[`finance > 1337 > amount > with min, max and dec option 1`] = `"20.48098"`; exports[`finance > 1337 > amount > with min, max, dec and symbol option 1`] = `"#20.48098"`; @@ -288,26 +224,12 @@ exports[`finance > 1337 > ethereumAddress 1`] = `"0x536a7b5fa28d2f9bb79ca46ea394 exports[`finance > 1337 > iban > noArgs 1`] = `"FO2200532700604734"`; -exports[`finance > 1337 > iban > with formatted 1`] = `"FO22 0053 2700 6047 34"`; - -exports[`finance > 1337 > iban > with formatted and countryCode 1`] = `"DE04 0033 2713 1474 7007 41"`; - exports[`finance > 1337 > iban > with formatted and countryCode option 1`] = `"DE04 0033 2713 1474 7007 41"`; exports[`finance > 1337 > iban > with formatted option 1`] = `"FO22 0053 2700 6047 34"`; exports[`finance > 1337 > litecoinAddress 1`] = `"LhsjwgYJ7oC8ZrMNmqzLbhEubpcw"`; -exports[`finance > 1337 > mask > noArgs 1`] = `"(...2124)"`; - -exports[`finance > 1337 > mask > with ellipsis 1`] = `"(...2124)"`; - -exports[`finance > 1337 > mask > with length 1`] = `"(...21243)"`; - -exports[`finance > 1337 > mask > with length, parenthesis and ellipsis 1`] = `"(...21243)"`; - -exports[`finance > 1337 > mask > with parenthesis 1`] = `"(...2124)"`; - exports[`finance > 1337 > maskedNumber > noArgs 1`] = `"(...2124)"`; exports[`finance > 1337 > maskedNumber > with length 1`] = `"(...21243)"`; diff --git a/test/modules/finance-iban.spec.ts b/test/modules/finance-iban.spec.ts index 4d801aa570f..f699ada4121 100644 --- a/test/modules/finance-iban.spec.ts +++ b/test/modules/finance-iban.spec.ts @@ -11,7 +11,10 @@ describe('finance_iban', () => { describe('generic IBAN country checks', () => { it.each(ibanLib.formats.map((entry) => entry.country))('%s', (country) => { expect(country).toMatch(/^[A-Z]{2}$/); - const actual = faker.finance.iban(true, country); + const actual = faker.finance.iban({ + formatted: true, + countryCode: country, + }); expect(actual).toMatch(new RegExp(`^${country}`)); expect(actual).toSatisfy(validator.isIBAN); @@ -33,7 +36,10 @@ describe('finance_iban', () => { // example IBAN GE29 NB00 0000 0101 9049 17 - const iban = faker.finance.iban(false, 'GE'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'GE', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -93,7 +99,10 @@ describe('finance_iban', () => { // Account Code 16 digits // Total Length 24 chars - const iban = faker.finance.iban(false, 'PK'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'PK', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -159,7 +168,10 @@ describe('finance_iban', () => { // Chiffre d'indicatif national 0 // Numéro de compte bancaire 0519786457841326 - const iban = faker.finance.iban(false, 'TR'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'TR', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -229,7 +241,10 @@ describe('finance_iban', () => { // example IBAN AZ21 NABZ 0000 0000 1370 1000 1944 - const iban = faker.finance.iban(false, 'AZ'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'AZ', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -288,7 +303,10 @@ describe('finance_iban', () => { // example IBAN CR05 0152 0200 1026 2840 66 - const iban = faker.finance.iban(false, 'CR'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'CR', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -336,7 +354,10 @@ describe('finance_iban', () => { // National check digit 1 digit // Bank account number 16 digit - const iban = faker.finance.iban(false, 'AL'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'AL', + }); const ibanFormated = prettyPrintIban(iban); expect(iban).toSatisfy(validator.isIBAN); diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index db60a9b3956..3bf4a2c2509 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -28,10 +28,6 @@ describe('finance', () => { 'transactionDescription' ); - t.describe('account', (t) => { - t.it('noArgs').it('with length', 10); - }); - t.describe('accountNumber', (t) => { t.it('noArgs') .it('with length', 10) @@ -61,17 +57,7 @@ describe('finance', () => { dec: 5, symbol: '#', autoFormat: false, - }) - .it('with min', 10) - .it('with leagcy max', undefined, 50) - .it('with leagcy dec', undefined, undefined, 5) - .it( - 'with min, leagcy max, leagcy dec and leagcy symbol', - 10, - 50, - 5, - '$' - ); + }); }); t.describe('bic', (t) => { @@ -84,9 +70,7 @@ describe('finance', () => { .it('with formatted and countryCode option', { formatted: true, countryCode: 'DE', - }) - .it('with formatted', true) - .it('with formatted and countryCode', true, 'DE'); + }); }); t.describe('creditCardNumber', (t) => { @@ -96,14 +80,6 @@ describe('finance', () => { .it('with issuer option mastercard', { issuer: 'mastercard' }); }); - t.describe('mask', (t) => { - t.it('noArgs') - .it('with length', 5) - .it('with parenthesis', undefined, true) - .it('with ellipsis', undefined, undefined, true) - .it('with length, parenthesis and ellipsis', 5, true, true); - }); - t.describe('maskedNumber', (t) => { t.it('noArgs') .it('with length', 5) @@ -120,28 +96,6 @@ describe('finance', () => { describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( 'random seeded tests for seed %i', () => { - describe('account()', () => { - it('should supply a default length', () => { - const accountNumber = faker.finance.account(); - - expect(accountNumber).toBeTruthy(); - expect( - accountNumber, - 'The length of the account number should be 8 characters long' - ).toHaveLength(8); - }); - - it('should have same length as given length number', () => { - const accountNumber = faker.finance.account(16); - - expect(accountNumber).toBeTruthy(); - expect( - accountNumber, - 'The length of the account number should match the given number' - ).toHaveLength(16); - }); - }); - describe('accountNumber()', () => { it('should supply a default length', () => { const accountNumber = faker.finance.accountNumber(); @@ -191,31 +145,6 @@ describe('finance', () => { }); }); - describe('mask()', () => { - it('should set a default length', () => { - const expected = 4; // default account mask length - const mask = faker.finance.mask(undefined, false, false); - - expect( - mask, - `The expected default mask length is ${expected} but it was ${mask.length}` - ).toHaveLength(expected); - }); - - it('should set a specified length', () => { - let expected = faker.number.int(20); - - expected = expected || 4; - - const mask = faker.finance.mask(expected, false, false); // the length of mask picks 4 if the random number generator picks 0 - - expect( - mask, - `The expected default mask length is ${expected} but it was ${mask.length}` - ).toHaveLength(expected); - }); - }); - describe('maskedNumber()', () => { it('should return contain parenthesis, ellipsis and have a length of 4 by default', () => { const actual = faker.finance.maskedNumber(); @@ -264,10 +193,12 @@ describe('finance', () => { expect(+amount).toBeLessThanOrEqual(1000); }); + // TODO @Shinigami92 2024-03-09: is this whole test wrong? + // duplicate of line 232 it('should use the default decimal location when not passing arguments', () => { let amount = faker.finance.amount(); - amount = faker.finance.amount(100, 100, 1); + amount = faker.finance.amount({ min: 100, max: 100, dec: 1 }); expect(amount).toBeTruthy(); expect(amount).toBe('100.0'); @@ -286,7 +217,7 @@ describe('finance', () => { }); it('should handle negative amounts', () => { - const amount = faker.finance.amount(-200, -1); + const amount = faker.finance.amount({ min: -200, max: -1 }); expect(amount).toBeTruthy(); expect(amount).toBeTypeOf('string'); @@ -295,7 +226,7 @@ describe('finance', () => { }); it('should handle argument dec', () => { - const amount = faker.finance.amount(100, 100, 1); + const amount = faker.finance.amount({ min: 100, max: 100, dec: 1 }); expect(amount).toBeTruthy(); expect(amount).toBeTypeOf('string'); @@ -303,7 +234,7 @@ describe('finance', () => { }); it('should handle argument dec = 0', () => { - const amount = faker.finance.amount(100, 100, 0); + const amount = faker.finance.amount({ min: 100, max: 100, dec: 0 }); expect(amount).toBeTruthy(); expect(amount).toBeTypeOf('string'); @@ -314,13 +245,13 @@ describe('finance', () => { 'should return unformatted if autoformat is %s', (autoFormat) => { const number = 6000; - const amount = faker.finance.amount( - number, - number, - 0, - undefined, - autoFormat - ); + const amount = faker.finance.amount({ + min: number, + max: number, + dec: 0, + symbol: undefined, + autoFormat, + }); expect(amount).toBe(number.toString()); } @@ -333,13 +264,13 @@ describe('finance', () => { minimumFractionDigits: decimalPlaces, }); - const amount = faker.finance.amount( - number, - number, - decimalPlaces, - undefined, - true - ); + const amount = faker.finance.amount({ + min: number, + max: number, + dec: decimalPlaces, + symbol: undefined, + autoFormat: true, + }); expect(amount).toStrictEqual(expected); }); @@ -562,7 +493,10 @@ describe('finance', () => { }); it('should return a specific and formally correct IBAN number', () => { - const iban = faker.finance.iban(false, 'DE'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'DE', + }); const bban = iban.substring(4) + iban.substring(0, 4); const countryCode = iban.substring(0, 2); @@ -577,7 +511,10 @@ describe('finance', () => { 'throws an error for unsupported country code "%s"', (unsupportedCountryCode) => expect(() => - faker.finance.iban(false, unsupportedCountryCode) + faker.finance.iban({ + formatted: false, + countryCode: unsupportedCountryCode, + }) ).toThrow( new FakerError( `Country code ${unsupportedCountryCode} not supported.` From b810ff84ffdcd33532a9727f358da54113513fdd Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 9 Mar 2024 10:30:23 +0100 Subject: [PATCH 2/5] remove test case --- test/modules/finance.spec.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index 3bf4a2c2509..80d67cb1856 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -193,17 +193,6 @@ describe('finance', () => { expect(+amount).toBeLessThanOrEqual(1000); }); - // TODO @Shinigami92 2024-03-09: is this whole test wrong? - // duplicate of line 232 - it('should use the default decimal location when not passing arguments', () => { - let amount = faker.finance.amount(); - - amount = faker.finance.amount({ min: 100, max: 100, dec: 1 }); - - expect(amount).toBeTruthy(); - expect(amount).toBe('100.0'); - }); - //TODO: add support for more currency and decimal options it('should not include a currency symbol by default', () => { const amount = faker.finance.amount(); From 934dab00a00dd26c0ec342295f55a8ed593c5f24 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 9 Mar 2024 10:31:39 +0100 Subject: [PATCH 3/5] omit symbol --- test/modules/finance.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index 80d67cb1856..24cc3c9fec5 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -238,7 +238,6 @@ describe('finance', () => { min: number, max: number, dec: 0, - symbol: undefined, autoFormat, }); @@ -257,7 +256,6 @@ describe('finance', () => { min: number, max: number, dec: decimalPlaces, - symbol: undefined, autoFormat: true, }); From 45155ee82bfd931ef613f6504f73eb89e9d69567 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 9 Mar 2024 10:34:22 +0100 Subject: [PATCH 4/5] add m-guide --- docs/guide/upgrading_v9/2727.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 docs/guide/upgrading_v9/2727.md diff --git a/docs/guide/upgrading_v9/2727.md b/docs/guide/upgrading_v9/2727.md new file mode 100644 index 00000000000..659d61f6351 --- /dev/null +++ b/docs/guide/upgrading_v9/2727.md @@ -0,0 +1,10 @@ +### Remove deprecated finance methods + +Removed deprecated finance methods + +| old | replacement | +| --------------------------------------------------------- | ------------------------------------------------------------- | +| `faker.finance.account` | `faker.finance.accountNumber` | +| `faker.finance.mask` | `faker.finance.maskedNumber` | +| `faker.finance.amount(min, max, dec, symbol, autoFormat)` | `faker.finance.amount({ min, max, dec, symbol, autoFormat })` | +| `faker.finance.iban(formatted, countryCode)` | `faker.finance.iban({ formatted, countryCode })` | From ee59bcd66362697d576ad52b64265aa5b6398337 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 9 Mar 2024 11:10:41 +0100 Subject: [PATCH 5/5] add test case --- test/modules/finance.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index 24cc3c9fec5..0b9a4d6cff7 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -214,6 +214,14 @@ describe('finance', () => { expect(+amount).toBeGreaterThanOrEqual(-200); }); + it('should use the default dec', () => { + const amount = faker.finance.amount({ min: 100, max: 100 }); + + expect(amount).toBeTruthy(); + expect(amount).toBeTypeOf('string'); + expect(amount).toBe('100.00'); + }); + it('should handle argument dec', () => { const amount = faker.finance.amount({ min: 100, max: 100, dec: 1 });