From 7dd19bea77f3217481481446e8501092f1873c8d Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sat, 15 Apr 2023 19:13:41 +0200 Subject: [PATCH 1/4] refactor(finance): rename account to accountNumber --- src/modules/finance/index.ts | 59 ++++++++++++++++++------- test/__snapshots__/finance.spec.ts.snap | 24 +++++++--- test/finance.spec.ts | 52 ++++++++++++++++++---- 3 files changed, 104 insertions(+), 31 deletions(-) diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 579bd89bcd9..c59387d66ed 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -1,5 +1,6 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; +import { deprecated } from '../../internal/deprecated'; import iban from './iban'; /** @@ -29,7 +30,7 @@ export interface Currency { * * For a random amount, use [`amount()`](https://next.fakerjs.dev/api/finance.html#amount). * - * For traditional bank accounts, use: [`account()`](https://next.fakerjs.dev/api/finance.html#account), [`accountName()`](https://next.fakerjs.dev/api/finance.html#accountname), [`bic()`](https://next.fakerjs.dev/api/finance.html#bic), [`iban()`](https://next.fakerjs.dev/api/finance.html#iban), [`pin()`](https://next.fakerjs.dev/api/finance.html#pin) and [`routingNumber()`](https://next.fakerjs.dev/api/finance.html#routingnumber). + * For traditional bank accounts, use: [`accountNumber()`](https://next.fakerjs.dev/api/finance.html#accountnumber), [`accountName()`](https://next.fakerjs.dev/api/finance.html#accountname), [`bic()`](https://next.fakerjs.dev/api/finance.html#bic), [`iban()`](https://next.fakerjs.dev/api/finance.html#iban), [`pin()`](https://next.fakerjs.dev/api/finance.html#pin) and [`routingNumber()`](https://next.fakerjs.dev/api/finance.html#routingnumber). * * For credit card related methods, use: [`creditCardNumber()`](https://next.fakerjs.dev/api/finance.html#creditcardnumber), [`creditCardCVV()`](https://next.fakerjs.dev/api/finance.html#creditcardcvv), [`creditCardIssuer()`](https://next.fakerjs.dev/api/finance.html#creditcardissuer), [`transactionDescription()`](https://next.fakerjs.dev/api/finance.html#transactiondescription) and [`transactionType()`](https://next.fakerjs.dev/api/finance.html#transactiontype). * @@ -59,8 +60,32 @@ export class FinanceModule { * faker.finance.account(5) // 32564 * * @since 2.0.1 + * + * @deprecated Use `faker.finance.accountNumber` instead. */ - account(length?: number): string; + 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. + * + * @param length The length of the account number. Defaults to `8`. + * + * @example + * faker.finance.accountNumber() // 92842238 + * faker.finance.accountNumber(5) // 32564 + * + * @since 8.0.0 + */ + accountNumber(length?: number): string; /** * Generates a random account number. * @@ -68,12 +93,12 @@ export class FinanceModule { * @param options.length The length of the account number. Defaults to `8`. * * @example - * faker.finance.account() // 92842238 - * faker.finance.account({ length: 5 }) // 32564 + * faker.finance.accountNumber() // 92842238 + * faker.finance.accountNumber({ length: 5 }) // 32564 * - * @since 2.0.1 + * @since 8.0.0 */ - account(options?: { + accountNumber(options?: { /** * The length of the account number. * @@ -88,13 +113,13 @@ export class FinanceModule { * @param optionsOrLength.length The length of the account number. Defaults to `8`. * * @example - * faker.finance.account() // 92842238 - * faker.finance.account(5) // 28736 - * faker.finance.account({ length: 5 }) // 32564 + * faker.finance.accountNumber() // 92842238 + * faker.finance.accountNumber(5) // 28736 + * faker.finance.accountNumber({ length: 5 }) // 32564 * - * @since 2.0.1 + * @since 8.0.0 */ - account( + accountNumber( optionsOrLength?: | number | { @@ -113,13 +138,13 @@ export class FinanceModule { * @param options.length The length of the account number. Defaults to `8`. * * @example - * faker.finance.account() // 92842238 - * faker.finance.account(5) // 28736 - * faker.finance.account({ length: 5 }) // 32564 + * faker.finance.accountNumber() // 92842238 + * faker.finance.accountNumber(5) // 28736 + * faker.finance.accountNumber({ length: 5 }) // 32564 * - * @since 2.0.1 + * @since 8.0.0 */ - account( + accountNumber( options: | number | { @@ -1185,7 +1210,7 @@ export class FinanceModule { const amount = this.amount(); const company = this.faker.company.name(); const transactionType = this.transactionType(); - const account = this.account(); + const account = this.accountNumber(); const card = this.mask(); const currency = this.currencyCode(); diff --git a/test/__snapshots__/finance.spec.ts.snap b/test/__snapshots__/finance.spec.ts.snap index 217bc437858..fe7a51b7191 100644 --- a/test/__snapshots__/finance.spec.ts.snap +++ b/test/__snapshots__/finance.spec.ts.snap @@ -4,10 +4,14 @@ exports[`finance > 42 > account > noArgs 1`] = `"37917755"`; exports[`finance > 42 > account > with length 1`] = `"3791775514"`; -exports[`finance > 42 > account > with length option 1`] = `"3791775514"`; - exports[`finance > 42 > accountName 1`] = `"Money Market Account"`; +exports[`finance > 42 > accountNumber > noArgs 1`] = `"37917755"`; + +exports[`finance > 42 > accountNumber > with length 1`] = `"3791775514"`; + +exports[`finance > 42 > accountNumber > with length option 1`] = `"3791775514"`; + exports[`finance > 42 > amount > noArgs 1`] = `"374.54"`; exports[`finance > 42 > amount > with leagcy dec 1`] = `"374.54011"`; @@ -104,10 +108,14 @@ exports[`finance > 1211 > account > noArgs 1`] = `"94872190"`; exports[`finance > 1211 > account > with length 1`] = `"9487219061"`; -exports[`finance > 1211 > account > with length option 1`] = `"9487219061"`; - exports[`finance > 1211 > accountName 1`] = `"Personal Loan Account"`; +exports[`finance > 1211 > accountNumber > noArgs 1`] = `"94872190"`; + +exports[`finance > 1211 > accountNumber > with length 1`] = `"9487219061"`; + +exports[`finance > 1211 > accountNumber > with length option 1`] = `"9487219061"`; + exports[`finance > 1211 > amount > noArgs 1`] = `"928.52"`; exports[`finance > 1211 > amount > with leagcy dec 1`] = `"928.52016"`; @@ -204,10 +212,14 @@ exports[`finance > 1337 > account > noArgs 1`] = `"25122540"`; exports[`finance > 1337 > account > with length 1`] = `"2512254032"`; -exports[`finance > 1337 > account > with length option 1`] = `"2512254032"`; - exports[`finance > 1337 > accountName 1`] = `"Money Market Account"`; +exports[`finance > 1337 > accountNumber > noArgs 1`] = `"25122540"`; + +exports[`finance > 1337 > accountNumber > with length 1`] = `"2512254032"`; + +exports[`finance > 1337 > accountNumber > with length option 1`] = `"2512254032"`; + exports[`finance > 1337 > amount > noArgs 1`] = `"262.02"`; exports[`finance > 1337 > amount > with leagcy dec 1`] = `"262.02467"`; diff --git a/test/finance.spec.ts b/test/finance.spec.ts index 864ddb3bf23..a99c4e317b0 100644 --- a/test/finance.spec.ts +++ b/test/finance.spec.ts @@ -27,6 +27,10 @@ describe('finance', () => { ); t.describe('account', (t) => { + t.it('noArgs').it('with length', 10); + }); + + t.describe('accountNumber', (t) => { t.it('noArgs') .it('with length', 10) .it('with length option', { length: 10 }); @@ -114,26 +118,58 @@ describe('finance', () => { for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { describe('account()', () => { it('should supply a default length', () => { - const accountNum = faker.finance.account(); + const accountNumber = faker.finance.account(); - expect(accountNum).toBeTruthy(); + expect(accountNumber).toBeTruthy(); expect( - accountNum, + accountNumber, 'The length of the account number should be 8 characters long' ).toHaveLength(8); }); - it('should be the the length fo given number', () => { - const accountNum = faker.finance.account(16); + it('should be the the length to given number', () => { + const accountNumber = faker.finance.account(16); - expect(accountNum).toBeTruthy(); + expect(accountNumber).toBeTruthy(); expect( - accountNum, - 'The length of the account number should match the given number' + 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(); + + expect(accountNumber).toBeTruthy(); + expect( + accountNumber, + 'The length of the account number should be 8 characters long' + ).toHaveLength(8); + }); + + it('should be the the length to given number', () => { + const accountNumber = faker.finance.accountNumber(16); + + expect(accountNumber).toBeTruthy(); + expect( + accountNumber, + 'The length of the account number should match the given number' + ).toHaveLength(16); + }); + + it('should be the the length option to given number', () => { + const accountNumber = faker.finance.accountNumber({ length: 12 }); + + expect(accountNumber).toBeTruthy(); + expect( + accountNumber, + 'The length of the account number should match the given number' + ).toHaveLength(12); + }); + }); + describe('accountName()', () => { it('should return a string', () => { const accountName = faker.finance.accountName(); From e60bdcf1db0b4eef3dee377881b6a8ea34ddffa3 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sun, 16 Apr 2023 12:30:32 +0200 Subject: [PATCH 2/4] add @see --- src/modules/finance/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index c59387d66ed..f4caa000fb1 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -55,6 +55,8 @@ export class FinanceModule { * * @param length The length of the account number. Defaults to `8`. * + * @see faker.finance.accountNumber() + * * @example * faker.finance.account() // 92842238 * faker.finance.account(5) // 32564 From 5b241c1fa8d13aaa8b83453269d9e5f64c476f9e Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Sun, 16 Apr 2023 12:32:49 +0200 Subject: [PATCH 3/4] update upgrading --- docs/guide/upgrading.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index 7618ab8457f..d0322a0b0fa 100644 --- a/docs/guide/upgrading.md +++ b/docs/guide/upgrading.md @@ -191,6 +191,10 @@ The `faker.address.*` methods will continue to work as an alias in v8 and v9, bu | `faker.address.streetPrefix` | _Removed_ | | `faker.address.streetSuffix` | _Removed_ | +### `faker.finance.account` changed to `faker.finance.accountNumber` + +The `faker.finance.account` method has been renamed to `faker.finance.accountNumber` to better reflect the data it returns and not to get confused with a user "Account". + ### Number methods of `faker.datatype` moved to new `faker.number` module The number-related methods previously found in `faker.datatype` have been moved to a new `faker.number` module. From a360d8ebd8c629da2a23a79446488b0b45a9ab33 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Tue, 18 Apr 2023 08:20:59 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Eric Cheng --- test/finance.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/finance.spec.ts b/test/finance.spec.ts index a99c4e317b0..5af487f895d 100644 --- a/test/finance.spec.ts +++ b/test/finance.spec.ts @@ -127,7 +127,7 @@ describe('finance', () => { ).toHaveLength(8); }); - it('should be the the length to given number', () => { + it('should have same length as given length number', () => { const accountNumber = faker.finance.account(16); expect(accountNumber).toBeTruthy(); @@ -149,7 +149,7 @@ describe('finance', () => { ).toHaveLength(8); }); - it('should be the the length to given number', () => { + it('should have same length as given length number', () => { const accountNumber = faker.finance.accountNumber(16); expect(accountNumber).toBeTruthy(); @@ -159,7 +159,7 @@ describe('finance', () => { ).toHaveLength(16); }); - it('should be the the length option to given number', () => { + it('should have same length as given length object', () => { const accountNumber = faker.finance.accountNumber({ length: 12 }); expect(accountNumber).toBeTruthy();