diff options
| author | Shinigami <[email protected]> | 2023-04-18 17:26:59 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-18 17:26:59 +0200 |
| commit | 5c3b6e032bdd0488c48b82c4395459be7ee50fb0 (patch) | |
| tree | 951832789f14725642ebdb7be3f34a303660be48 | |
| parent | fc13424b4d43bcdae6e2f2a4ffcf2130bbc357f6 (diff) | |
| download | faker-5c3b6e032bdd0488c48b82c4395459be7ee50fb0.tar.xz faker-5c3b6e032bdd0488c48b82c4395459be7ee50fb0.zip | |
refactor(finance): rename account to accountNumber (#2054)
| -rw-r--r-- | docs/guide/upgrading.md | 4 | ||||
| -rw-r--r-- | src/modules/finance/index.ts | 61 | ||||
| -rw-r--r-- | test/__snapshots__/finance.spec.ts.snap | 24 | ||||
| -rw-r--r-- | test/finance.spec.ts | 52 |
4 files changed, 110 insertions, 31 deletions
diff --git a/docs/guide/upgrading.md b/docs/guide/upgrading.md index 7618ab84..d0322a0b 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. diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index cca634c0..fba04ce8 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). * @@ -54,13 +55,39 @@ 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 * * @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. + * + * @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 */ - account(length?: number): string; + accountNumber(length?: number): string; /** * Generates a random account number. * @@ -68,12 +95,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 +115,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 +140,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 | { @@ -1191,7 +1218,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 217bc437..fe7a51b7 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 864ddb3b..5af487f8 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 have same length as given length 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 have same length as given length 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 have same length as given length object', () => { + 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(); |
