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): rename account to accountNumber #2054

Merged
merged 12 commits into from
Apr 18, 2023
Merged
59 changes: 42 additions & 17 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Faker } from '../..';
import { FakerError } from '../../errors/faker-error';
import { deprecated } from '../../internal/deprecated';
import iban from './iban';

/**
Expand Down Expand Up @@ -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).
*
Expand Down Expand Up @@ -59,21 +60,45 @@ 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.
*
* @param options An options object. Defaults to `{}`.
* @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.
*
Expand All @@ -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
| {
Expand All @@ -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
| {
Expand Down Expand Up @@ -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();

Expand Down
24 changes: 18 additions & 6 deletions test/__snapshots__/finance.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"`;
Expand Down Expand Up @@ -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"`;
Expand Down Expand Up @@ -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"`;
Expand Down
52 changes: 44 additions & 8 deletions test/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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();
Expand Down