Skip to content

Commit

Permalink
Merge branch 'main' into docs/usage-for-own-objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Sep 23, 2022
2 parents 35795b4 + 10aded2 commit 23dc6fc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
25 changes: 18 additions & 7 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ export class FinanceModule {

let address = this.faker.helpers.arrayElement(['1', '3']);

for (let i = 0; i < addressLength - 1; i++)
address += this.faker.helpers.arrayElement(
'123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split('')
);
address += this.faker.random.alphaNumeric(addressLength, {
casing: 'mixed',
bannedChars: '0OIl',
});

return address;
}
Expand Down Expand Up @@ -429,19 +429,30 @@ export class FinanceModule {
/**
* Generates a random SWIFT/BIC code based on the [ISO-9362](https://en.wikipedia.org/wiki/ISO_9362) format.
*
* @param options Options object.
* @param options.includeBranchCode Whether to include a three-digit branch code at the end of the generated code. Defaults to a random boolean value.
*
* @example
* faker.finance.bic() // 'WYAUPGX1432'
* faker.finance.bic() // 'WYAUPGX1'
* faker.finance.bic({ includeBranchCode: true }) // 'KCAUPGR1432'
* faker.finance.bic({ includeBranchCode: false }) // 'XDAFQGT7'
*
* @since 4.0.0
*/
bic(): string {
bic(
options: {
includeBranchCode?: boolean;
} = {}
): string {
const { includeBranchCode = this.faker.datatype.boolean() } = options;

const bankIdentifier = this.faker.random.alpha({
count: 4,
casing: 'upper',
});
const countryCode = this.faker.helpers.arrayElement(iban.iso3166);
const locationCode = this.faker.random.alphaNumeric(2, { casing: 'upper' });
const branchCode = this.faker.datatype.boolean()
const branchCode = includeBranchCode
? this.faker.datatype.boolean()
? this.faker.random.alphaNumeric(3, { casing: 'upper' })
: 'XXX'
Expand Down
18 changes: 12 additions & 6 deletions test/__snapshots__/finance.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ exports[`finance > 42 > amount > with min 1`] = `"380.79"`;

exports[`finance > 42 > amount > with min and max and dec and symbol 1`] = `"$24.98160"`;

exports[`finance > 42 > bic 1`] = `"JUYEPSSLXXX"`;
exports[`finance > 42 > bic > noArgs 1`] = `"UYETSCLL"`;

exports[`finance > 42 > bitcoinAddress 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1bZb"`;
exports[`finance > 42 > bic > with branch code 1`] = `"JUYEPSSL5G5"`;

exports[`finance > 42 > bitcoinAddress 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1bZbB"`;

exports[`finance > 42 > creditCardCVV 1`] = `"379"`;

Expand Down Expand Up @@ -80,9 +82,11 @@ exports[`finance > 1211 > amount > with min 1`] = `"929.24"`;

exports[`finance > 1211 > amount > with min and max and dec and symbol 1`] = `"$47.14081"`;

exports[`finance > 1211 > bic 1`] = `"YLXUDE4Z"`;
exports[`finance > 1211 > bic > noArgs 1`] = `"LXUFBTZ15O7"`;

exports[`finance > 1211 > bic > with branch code 1`] = `"YLXUDE4ZXXX"`;

exports[`finance > 1211 > bitcoinAddress 1`] = `"1TMe8Z3EaFdLqmaGKP1LEEJQVriSZRZdsAUc9n"`;
exports[`finance > 1211 > bitcoinAddress 1`] = `"1TMe8Z3EaFdLqmaGKP1LEEJQVriSZRZdsAUc9nC"`;

exports[`finance > 1211 > creditCardCVV 1`] = `"948"`;

Expand Down Expand Up @@ -144,9 +148,11 @@ exports[`finance > 1337 > amount > with min 1`] = `"269.40"`;

exports[`finance > 1337 > amount > with min and max and dec and symbol 1`] = `"$20.48098"`;

exports[`finance > 1337 > bic 1`] = `"GOEFFIJG"`;
exports[`finance > 1337 > bic > noArgs 1`] = `"OEFHLYG1"`;

exports[`finance > 1337 > bic > with branch code 1`] = `"GOEFFIJGXXX"`;

exports[`finance > 1337 > bitcoinAddress 1`] = `"3adhxs2jewAgkYgJi7No6Cn8JZar"`;
exports[`finance > 1337 > bitcoinAddress 1`] = `"3adhxs2jewAgkYgJi7No6Cn8JZarS"`;

exports[`finance > 1337 > creditCardCVV 1`] = `"251"`;

Expand Down
15 changes: 13 additions & 2 deletions test/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('finance', () => {
'litecoinAddress',
'creditCardCVV',
'ethereumAddress',
'bic',
'transactionDescription'
);

Expand All @@ -45,6 +44,10 @@ describe('finance', () => {
.it('with min and max and dec and symbol', 10, 50, 5, '$');
});

t.describe('bic', (t) => {
t.it('noArgs').it('with branch code', { includeBranchCode: true });
});

t.describe('iban', (t) => {
t.it('noArgs')
.it('with formatted', true)
Expand Down Expand Up @@ -481,13 +484,21 @@ describe('finance', () => {
});

describe('bic()', () => {
it('should return a random yet formally correct BIC number', () => {
it('should return a BIC number', () => {
const bic = faker.finance.bic();

expect(bic).toBeTypeOf('string');
expect(bic).toMatch(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/);
expect(ibanLib.iso3166).toContain(bic.substring(4, 6));
});

it('should return a BIC number with branch code', () => {
const bic = faker.finance.bic({ includeBranchCode: true });

expect(bic).toBeTypeOf('string');
expect(bic).toMatch(/^[A-Z]{6}[A-Z0-9]{2}[A-Z0-9]{3}$/);
expect(ibanLib.iso3166).toContain(bic.substring(4, 6));
});
});

describe('transactionDescription()', () => {
Expand Down

0 comments on commit 23dc6fc

Please sign in to comment.