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

fix(finance.bic): remove hardcoded elements and simplify function #1171

Merged
merged 7 commits into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/modules/finance/index.ts
Expand Up @@ -390,29 +390,23 @@ export class Finance {
}

/**
* Generates a random bic.
* Generates a random SWIFT/BIC code.
*
* @example
* faker.finance.bic() // 'WYAUPGX1432'
*/
bic(): string {
const vowels = ['A', 'E', 'I', 'O', 'U'];
const prob = this.faker.datatype.number(100);
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()
? this.faker.random.alphaNumeric(3, { casing: 'upper' })
: '';

return [
this.faker.helpers.replaceSymbols('???'),
this.faker.helpers.arrayElement(vowels),
this.faker.helpers.arrayElement(iban.iso3166),
this.faker.helpers.replaceSymbols('?'),
'1',
prob < 10
? this.faker.helpers.replaceSymbols(
`?${this.faker.helpers.arrayElement(vowels)}?`
)
: prob < 40
? this.faker.helpers.replaceSymbols('###')
: '',
].join('');
return `${bankIdentifier}${countryCode}${locationCode}${branchCode}`;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/finance.spec.ts.snap
Expand Up @@ -6,7 +6,7 @@ exports[`finance > seed: 42 > accountName() 1`] = `"Money Market Account"`;

exports[`finance > seed: 42 > amount() 1`] = `"374.54"`;

exports[`finance > seed: 42 > bic() 1`] = `"UYEOSCP1514"`;
exports[`finance > seed: 42 > bic() 1`] = `"JUYEPSSL5G5"`;

exports[`finance > seed: 42 > bitcoinAddress() 1`] = `"3XbJMAAara64sSkA9HD24YHQWd1b"`;

Expand Down Expand Up @@ -42,7 +42,7 @@ exports[`finance > seed: 1211 > accountName() 1`] = `"Personal Loan Account"`;

exports[`finance > seed: 1211 > amount() 1`] = `"928.52"`;

exports[`finance > seed: 1211 > bic() 1`] = `"LXUEBTZ1"`;
exports[`finance > seed: 1211 > bic() 1`] = `"YLXUDE4Z"`;

exports[`finance > seed: 1211 > bitcoinAddress() 1`] = `"1TMe8Z3EaFdLqmaGKP1LEEJQVriSZRZdsA"`;

Expand Down Expand Up @@ -78,7 +78,7 @@ exports[`finance > seed: 1337 > accountName() 1`] = `"Money Market Account"`;

exports[`finance > seed: 1337 > amount() 1`] = `"262.02"`;

exports[`finance > seed: 1337 > bic() 1`] = `"OEFELYL1032"`;
exports[`finance > seed: 1337 > bic() 1`] = `"GOEFFIJG"`;

exports[`finance > seed: 1337 > bitcoinAddress() 1`] = `"3adhxs2jewAgkYgJi7No6Cn8JZa"`;

Expand Down