aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/finance.spec.ts603
1 files changed, 315 insertions, 288 deletions
diff --git a/test/finance.spec.ts b/test/finance.spec.ts
index 71e9b76d..32bfc317 100644
--- a/test/finance.spec.ts
+++ b/test/finance.spec.ts
@@ -9,22 +9,22 @@ const seedRuns = [
expectations: {
account: '37917755',
accountName: 'Money Market Account',
+ routingNumber: '379177554',
+ mask: '(...3791)',
amount: '374.54',
- bic: 'UYEOSCP1514',
- bitcoinAddress: '3XbJMAAara64sSkA9HD24YHQWd1b',
- creditCardCVV: '379',
- creditCardNumber: '3581-7755-1410-0486',
+ transactionType: 'withdrawal',
currencyCode: 'IQD',
currencyName: 'Iraqi Dinar',
currencySymbol: '₱',
+ bitcoinAddress: '3XbJMAAara64sSkA9HD24YHQWd1b',
+ litecoinAddress: '3XbJMAAara64sSkA9HD24YHQWd1b',
+ creditCardNumber: '3581-7755-1410-0486',
+ creditCardCVV: '379',
ethereumAddress: '0x8be4abdd39321ad7d3fe01ffce404f4d6db0906b',
iban: 'GT30Y75110867098F1E3542612J4',
- litecoinAddress: '3XbJMAAara64sSkA9HD24YHQWd1b',
- mask: '(...3791)',
- routingNumber: '379177554',
+ bic: 'UYEOSCP1514',
transactionDescription:
'deposit transaction at Wiegand, Deckow and Renner using card ending with ***(...6009) for SGD 374.54 in account ***00483617',
- transactionType: 'withdrawal',
},
},
{
@@ -32,22 +32,22 @@ const seedRuns = [
expectations: {
account: '25122540',
accountName: 'Money Market Account',
+ routingNumber: '251225401',
+ mask: '(...2512)',
amount: '262.02',
- bic: 'OEFELTL1032',
- bitcoinAddress: '3adhxs2jewAgkYgJi7No6Cn8JZa',
- creditCardCVV: '251',
- creditCardNumber: '6011-6212-2540-3255-2392',
+ transactionType: 'withdrawal',
currencyCode: 'FJD',
currencyName: 'Fiji Dollar',
currencySymbol: '$',
+ bitcoinAddress: '3adhxs2jewAgkYgJi7No6Cn8JZa',
+ litecoinAddress: 'Madhxs2jewAgkYgJi7No6Cn8JZar',
+ creditCardNumber: '6011-6212-2540-3255-2392',
+ creditCardCVV: '251',
ethereumAddress: '0x5c346ba075bd57f5a62b82d72af39cbbb07a98cb',
iban: 'FO7710540350900318',
- litecoinAddress: 'Madhxs2jewAgkYgJi7No6Cn8JZar',
- mask: '(...2512)',
- routingNumber: '251225401',
+ bic: 'OEFELTL1032',
transactionDescription:
'deposit transaction at Cronin - Effertz using card ending with ***(...1830) for PEN 262.02 in account ***55239273',
- transactionType: 'withdrawal',
},
},
{
@@ -55,22 +55,22 @@ const seedRuns = [
expectations: {
account: '94872190',
accountName: 'Personal Loan Account',
+ routingNumber: '948721904',
+ mask: '(...9487)',
amount: '928.52',
- bic: 'LXUEBTZ1',
- bitcoinAddress: '1TMe8Z3EaFdLqmaGKP1LEEJQVriSZRZdsA',
- creditCardCVV: '948',
- creditCardNumber: '4872190616276',
+ transactionType: 'invoice',
currencyCode: 'XDR',
currencyName: 'SDR',
currencySymbol: '₭',
+ bitcoinAddress: '1TMe8Z3EaFdLqmaGKP1LEEJQVriSZRZdsA',
+ litecoinAddress: 'MTMe8Z3EaFdLqmaGKP1LEEJQVriSZRZds',
+ creditCardNumber: '4872190616276',
+ creditCardCVV: '948',
ethereumAddress: '0xeadb42f0e3f4a973fab0aeefce96dfcf49cd438d',
iban: 'TN0382001124170679299069',
- litecoinAddress: 'MTMe8Z3EaFdLqmaGKP1LEEJQVriSZRZds',
- mask: '(...9487)',
- routingNumber: '948721904',
+ bic: 'LXUEBTZ1',
transactionDescription:
'deposit transaction at Trantow - Sanford using card ending with ***(...8076) for PYG 928.52 in account ***62743167',
- transactionType: 'invoice',
},
},
];
@@ -78,21 +78,21 @@ const seedRuns = [
const functionNames = [
'account',
'accountName',
+ 'routingNumber',
+ 'mask',
'amount',
- 'bic',
- 'bitcoinAddress',
- 'creditCardCVV',
- 'creditCardNumber',
+ 'transactionType',
'currencyCode',
'currencyName',
'currencySymbol',
+ 'bitcoinAddress',
+ 'litecoinAddress',
+ 'creditCardNumber',
+ 'creditCardCVV',
'ethereumAddress',
'iban',
- 'litecoinAddress',
- 'mask',
- 'routingNumber',
+ 'bic',
'transactionDescription',
- 'transactionType',
];
const NON_SEEDED_BASED_RUN = 5;
@@ -107,7 +107,9 @@ describe('finance', () => {
for (const functionName of functionNames) {
it(`${functionName}()`, () => {
faker.seed(seed);
+
const actual = faker.finance[functionName]();
+
expect(actual).toEqual(expectations[functionName]);
});
}
@@ -119,9 +121,10 @@ describe('finance', () => {
describe(`random seeded tests for seed ${faker.seedValue}`, () => {
for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) {
- describe('account(length)', () => {
+ describe('account()', () => {
it('should supply a default length', () => {
const accountNum = faker.finance.account();
+
expect(accountNum).toBeTruthy();
expect(
accountNum,
@@ -131,6 +134,7 @@ describe('finance', () => {
it('should supply a default length if a zero is passed', () => {
const accountNum = faker.finance.account(0);
+
expect(accountNum).toBeTruthy();
expect(
accountNum,
@@ -140,6 +144,7 @@ describe('finance', () => {
it('should be the the length fo given number', () => {
const accountNum = faker.finance.account(16);
+
expect(accountNum).toBeTruthy();
expect(
accountNum,
@@ -147,310 +152,332 @@ describe('finance', () => {
).toHaveLength(16);
});
});
- }
- });
- describe('accountName()', () => {
- const accountName = faker.finance.accountName();
- expect(accountName).toBeTruthy();
- expect(typeof accountName).toBe('string');
- });
+ describe('accountName()', () => {
+ const accountName = faker.finance.accountName();
- describe('amount(min, max, dec, symbol)', () => {
- it('should use the default amounts when not passing arguments', () => {
- const amount = faker.finance.amount();
+ expect(accountName).toBeTruthy();
+ expect(typeof accountName).toBe('string');
+ });
- expect(amount).toBeTruthy();
- expect(+amount, 'the amount should be greater than 0').greaterThan(0);
- expect(+amount, 'the amount should be less than 1001').lessThan(1001);
- });
+ describe('routingNumber()', () => {
+ const routingNumber = faker.finance.routingNumber();
- it('should use the default decimal location when not passing arguments', () => {
- let amount = faker.finance.amount();
+ expect(typeof routingNumber).toBe('string');
+ });
- amount = faker.finance.amount(100, 100, 1);
+ describe('mask()', () => {
+ it('should set a default length', () => {
+ const expected = 4; //default account mask length
+ const mask = faker.finance.mask(null, false, false);
- expect(amount).toBeTruthy();
- expect(amount, 'the amount should be equal 100.0').toStrictEqual('100.0');
- });
+ expect(
+ mask,
+ `The expected default mask length is ${expected} but it was ${mask.length}`
+ ).toHaveLength(expected);
+ });
- //TODO: add support for more currency and decimal options
- it('should not include a currency symbol by default', () => {
- const amount = faker.finance.amount();
+ it('should set a specified length', () => {
+ let expected = faker.datatype.number(20);
- expect(
- amount,
- 'The expected match should not include a currency symbol'
- ).match(/[0-9.]/);
- });
+ expected =
+ expected === 0 || !expected || typeof expected == 'undefined'
+ ? 4
+ : expected;
- it('it should handle negative amounts', () => {
- const amount = faker.finance.amount(-200, -1);
+ const mask = faker.finance.mask(expected, false, false); //the length of mask picks 4 if the random number generator picks 0
- expect(amount).toBeTruthy();
- expect(+amount, 'the amount should be less than 0').lessThan(0);
- expect(+amount, 'the amount should be greater than -201').greaterThan(
- -201
- );
- });
+ expect(
+ mask,
+ `The expected default mask length is ${expected} but it was ${mask.length}`
+ ).toHaveLength(expected);
+ });
+ });
- it('it should handle argument dec', () => {
- const amount = faker.finance.amount(100, 100, 1);
+ describe('amount()', () => {
+ it('should use the default amounts when not passing arguments', () => {
+ const amount = faker.finance.amount();
- expect(amount).toBeTruthy();
- expect(amount, 'the amount should be equal 100.0').toStrictEqual('100.0');
- });
+ expect(amount).toBeTruthy();
+ expect(+amount, 'the amount should be greater than 0').greaterThan(0);
+ expect(+amount, 'the amount should be less than 1001').lessThan(1001);
+ });
- it('it should handle argument dec = 0', () => {
- const amount = faker.finance.amount(100, 100, 0);
+ it('should use the default decimal location when not passing arguments', () => {
+ let amount = faker.finance.amount();
- expect(amount).toBeTruthy();
- expect(amount, 'the amount should be equal 100').toStrictEqual('100');
- });
+ amount = faker.finance.amount(100, 100, 1);
- it('it should return a string', () => {
- const amount = faker.finance.amount(100, 100, 0);
+ expect(amount).toBeTruthy();
+ expect(amount, 'the amount should be equal 100.0').toStrictEqual(
+ '100.0'
+ );
+ });
- expect(amount).toBeTruthy();
- expect(typeof amount, 'the amount type should be string').toBe('string');
- });
+ //TODO: add support for more currency and decimal options
+ it('should not include a currency symbol by default', () => {
+ const amount = faker.finance.amount();
+
+ expect(
+ amount,
+ 'The expected match should not include a currency symbol'
+ ).match(/[0-9.]/);
+ });
+
+ it('it should handle negative amounts', () => {
+ const amount = faker.finance.amount(-200, -1);
+
+ expect(amount).toBeTruthy();
+ expect(+amount, 'the amount should be less than 0').lessThan(0);
+ expect(+amount, 'the amount should be greater than -201').greaterThan(
+ -201
+ );
+ });
+
+ it('it should handle argument dec', () => {
+ const amount = faker.finance.amount(100, 100, 1);
+
+ expect(amount).toBeTruthy();
+ expect(amount, 'the amount should be equal 100.0').toStrictEqual(
+ '100.0'
+ );
+ });
+
+ it('it should handle argument dec = 0', () => {
+ const amount = faker.finance.amount(100, 100, 0);
- [false, undefined].forEach((autoFormat) => {
- it(`should return unformatted if autoformat is ${autoFormat}`, () => {
- const number = 6000;
- const amount = faker.finance.amount(
- number,
- number,
- 0,
- undefined,
- autoFormat
+ expect(amount).toBeTruthy();
+ expect(amount, 'the amount should be equal 100').toStrictEqual('100');
+ });
+
+ it('it should return a string', () => {
+ const amount = faker.finance.amount(100, 100, 0);
+
+ expect(amount).toBeTruthy();
+ expect(typeof amount, 'the amount type should be string').toBe(
+ 'string'
+ );
+ });
+
+ it.each([false, undefined])(
+ 'should return unformatted if autoformat is %s',
+ (autoFormat) => {
+ const number = 6000;
+ const amount = faker.finance.amount(
+ number,
+ number,
+ 0,
+ undefined,
+ autoFormat
+ );
+
+ expect(amount).toStrictEqual(number.toString());
+ }
);
- expect(amount).toStrictEqual(number.toString());
+ it('should return the number formatted on the current locale', () => {
+ const number = 6000;
+ const decimalPlaces = 2;
+ const expected = number.toLocaleString(undefined, {
+ minimumFractionDigits: decimalPlaces,
+ });
+
+ const amount = faker.finance.amount(
+ number,
+ number,
+ decimalPlaces,
+ undefined,
+ true
+ );
+
+ expect(amount).toStrictEqual(expected);
+ });
});
- });
- it('should return the number formatted on the current locale', () => {
- const number = 6000;
- const decimalPlaces = 2;
- const expected = number.toLocaleString(undefined, {
- minimumFractionDigits: decimalPlaces,
+ describe('transactionType()', () => {
+ const transactionType = faker.finance.transactionType();
+
+ expect(typeof transactionType).toBe('string');
});
- const amount = faker.finance.amount(
- number,
- number,
- decimalPlaces,
- undefined,
- true
- );
+ describe('currencyCode()', () => {
+ const currencyCode = faker.finance.currencyCode();
- expect(amount).toStrictEqual(expected);
- });
- });
+ expect(typeof currencyCode).toBe('string');
+ expect(currencyCode).match(/^[A-Z]{3}$/);
+ });
- describe('bic()', () => {
- it('returns a random yet formally correct BIC number', () => {
- const bic = faker.finance.bic();
- const expr = new RegExp(
- `^[A-Z]{4}(${ibanLib.iso3166.join(
- '|'
- )})[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?\$`,
- 'i'
- );
- expect(typeof bic).toBe('string');
- expect(bic).match(expr);
- });
- });
+ describe('currencyName()', () => {
+ const currencyName = faker.finance.currencyName();
- describe('bitcoinAddress', () => {
- const bitcoinAddress = faker.finance.bitcoinAddress();
- /**
- * Note: Although the total length of a Bitcoin address can be 25-33 characters, regex quantifiers only check the preceding token
- * Therefore we take one from the total length of the address not including the first character ([13])
- */
+ expect(typeof currencyName).toBe('string');
+ });
- expect(bitcoinAddress).toBeTruthy();
- expect(typeof bitcoinAddress).toBe('string');
- expect(bitcoinAddress).match(/^[13][a-km-zA-HJ-NP-Z1-9]{24,33}$/);
- });
+ describe('currencySymbol()', () => {
+ const currencySymbol = faker.finance.currencySymbol();
- describe('creditCardCVV', () => {
- const cvv = faker.finance.creditCardCVV();
- expect(typeof cvv).toBe('string');
- expect(cvv).match(/\d{3}/);
- expect(
- cvv,
- 'The length of the cvv should be 3 characters long'
- ).toHaveLength(3);
- });
+ expect(typeof currencySymbol).toBe('string');
+ });
- describe('creditCardNumber', () => {
- it('returns a random credit card number', () => {
- let number = faker.finance.creditCardNumber();
- number = number.replace(/\D/g, ''); // remove formatting
- console.log('version:', process.version, number, number.length);
- expect(number.length).greaterThanOrEqual(13);
- expect(number.length).lessThanOrEqual(20);
- expect(number).match(/^\d{13,20}$/);
- expect(luhnCheck(number)).toBeTruthy();
- });
+ describe('bitcoinAddress()', () => {
+ const bitcoinAddress = faker.finance.bitcoinAddress();
+ /**
+ * Note: Although the total length of a Bitcoin address can be 25-33 characters, regex quantifiers only check the preceding token
+ * Therefore we take one from the total length of the address not including the first character ([13])
+ */
- it('returns a valid credit card number', () => {
- expect(luhnCheck(faker.finance.creditCardNumber(''))).toBeTruthy();
- expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
- expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
- expect(luhnCheck(faker.finance.creditCardNumber('visa'))).toBeTruthy();
- expect(
- luhnCheck(faker.finance.creditCardNumber('mastercard'))
- ).toBeTruthy();
- expect(
- luhnCheck(faker.finance.creditCardNumber('discover'))
- ).toBeTruthy();
- expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
- expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
- });
+ expect(bitcoinAddress).toBeTruthy();
+ expect(typeof bitcoinAddress).toBe('string');
+ expect(bitcoinAddress).match(/^[13][a-km-zA-HJ-NP-Z1-9]{24,33}$/);
+ });
- it('returns a correct credit card number when issuer provided', () => {
- //TODO: implement checks for each format with regexp
- const visa = faker.finance.creditCardNumber('visa');
- expect(visa).match(/^4(([0-9]){12}|([0-9]){3}(\-([0-9]){4}){3})$/);
- expect(luhnCheck(visa)).toBeTruthy();
-
- const mastercard = faker.finance.creditCardNumber('mastercard');
- expect(mastercard).match(/^(5[1-5]\d{2}|6771)(\-\d{4}){3}$/);
- expect(luhnCheck(mastercard)).toBeTruthy();
-
- const discover = faker.finance.creditCardNumber('discover');
-
- expect(luhnCheck(discover)).toBeTruthy();
-
- const american_express =
- faker.finance.creditCardNumber('american_express');
- expect(luhnCheck(american_express)).toBeTruthy();
- const diners_club = faker.finance.creditCardNumber('diners_club');
- expect(luhnCheck(diners_club)).toBeTruthy();
- const jcb = faker.finance.creditCardNumber('jcb');
- expect(luhnCheck(jcb)).toBeTruthy();
- const switchC = faker.finance.creditCardNumber('mastercard');
- expect(luhnCheck(switchC)).toBeTruthy();
- const solo = faker.finance.creditCardNumber('solo');
- expect(luhnCheck(solo)).toBeTruthy();
- const maestro = faker.finance.creditCardNumber('maestro');
- expect(luhnCheck(maestro)).toBeTruthy();
- const laser = faker.finance.creditCardNumber('laser');
- expect(luhnCheck(laser)).toBeTruthy();
- const instapayment = faker.finance.creditCardNumber('instapayment');
- expect(luhnCheck(instapayment)).toBeTruthy();
- });
+ describe('litecoinAddress()', () => {
+ const litecoinAddress = faker.finance.litecoinAddress();
- it('returns custom formated strings', () => {
- let number = faker.finance.creditCardNumber('###-###-##L');
- expect(number).match(/^\d{3}\-\d{3}\-\d{3}$/);
- expect(luhnCheck(number)).toBeTruthy();
+ expect(typeof litecoinAddress).toBe('string');
+ expect(litecoinAddress).match(/^[LM3][1-9a-km-zA-HJ-NP-Z]{25,32}$/);
+ });
- number = faker.finance.creditCardNumber('234[5-9]#{999}L');
- expect(number).match(/^234[5-9]\d{1000}$/);
- expect(luhnCheck(number)).toBeTruthy();
- });
- });
+ describe('creditCardNumber()', () => {
+ it('should return a random credit card number', () => {
+ let number = faker.finance.creditCardNumber();
+ number = number.replace(/\D/g, ''); // remove formatting
+ console.log('version:', process.version, number, number.length);
- describe('currencyCode()', () => {
- const currencyCode = faker.finance.currencyCode();
- expect(typeof currencyCode).toBe('string');
- expect(currencyCode).match(/^[A-Z]{3}$/);
- });
+ expect(number.length).greaterThanOrEqual(13);
+ expect(number.length).lessThanOrEqual(20);
+ expect(number).match(/^\d{13,20}$/);
+ expect(luhnCheck(number)).toBeTruthy();
+ });
- describe('currencyName()', () => {
- const currencyName = faker.finance.currencyName();
- expect(typeof currencyName).toBe('string');
- });
+ it('should return a valid credit card number', () => {
+ expect(luhnCheck(faker.finance.creditCardNumber(''))).toBeTruthy();
+ expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
+ expect(
+ luhnCheck(faker.finance.creditCardNumber('visa'))
+ ).toBeTruthy();
+ expect(
+ luhnCheck(faker.finance.creditCardNumber('mastercard'))
+ ).toBeTruthy();
+ expect(
+ luhnCheck(faker.finance.creditCardNumber('discover'))
+ ).toBeTruthy();
+ expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
+ expect(luhnCheck(faker.finance.creditCardNumber())).toBeTruthy();
+ });
- describe('currencySymbol()', () => {
- const currencySymbol = faker.finance.currencySymbol();
- expect(typeof currencySymbol).toBe('string');
- });
+ it('should return a correct credit card number when issuer provided', () => {
+ //TODO: implement checks for each format with regexp
+ const visa = faker.finance.creditCardNumber('visa');
+ expect(visa).match(/^4(([0-9]){12}|([0-9]){3}(\-([0-9]){4}){3})$/);
+ expect(luhnCheck(visa)).toBeTruthy();
+
+ const mastercard = faker.finance.creditCardNumber('mastercard');
+ expect(mastercard).match(/^(5[1-5]\d{2}|6771)(\-\d{4}){3}$/);
+ expect(luhnCheck(mastercard)).toBeTruthy();
+
+ const discover = faker.finance.creditCardNumber('discover');
+
+ expect(luhnCheck(discover)).toBeTruthy();
+
+ const american_express =
+ faker.finance.creditCardNumber('american_express');
+ expect(luhnCheck(american_express)).toBeTruthy();
+ const diners_club = faker.finance.creditCardNumber('diners_club');
+ expect(luhnCheck(diners_club)).toBeTruthy();
+ const jcb = faker.finance.creditCardNumber('jcb');
+ expect(luhnCheck(jcb)).toBeTruthy();
+ const switchC = faker.finance.creditCardNumber('mastercard');
+ expect(luhnCheck(switchC)).toBeTruthy();
+ const solo = faker.finance.creditCardNumber('solo');
+ expect(luhnCheck(solo)).toBeTruthy();
+ const maestro = faker.finance.creditCardNumber('maestro');
+ expect(luhnCheck(maestro)).toBeTruthy();
+ const laser = faker.finance.creditCardNumber('laser');
+ expect(luhnCheck(laser)).toBeTruthy();
+ const instapayment = faker.finance.creditCardNumber('instapayment');
+ expect(luhnCheck(instapayment)).toBeTruthy();
+ });
- describe('ethereumAddress()', () => {
- const ethereumAddress = faker.finance.ethereumAddress();
- expect(typeof ethereumAddress).toBe('string');
- expect(ethereumAddress).match(/^(0x)[0-9a-f]{40}$/);
- });
+ it('should return custom formated strings', () => {
+ let number = faker.finance.creditCardNumber('###-###-##L');
+ expect(number).match(/^\d{3}\-\d{3}\-\d{3}$/);
+ expect(luhnCheck(number)).toBeTruthy();
- describe('iban()', () => {
- it('returns a random yet formally correct IBAN number', () => {
- const iban: string = faker.finance.iban();
- const bban = iban.substring(4) + iban.substring(0, 4);
- expect(
- ibanLib.mod97(ibanLib.toDigitString(bban)),
- 'the result should be equal to 1'
- ).toStrictEqual(1);
- });
+ number = faker.finance.creditCardNumber('234[5-9]#{999}L');
+ expect(number).match(/^234[5-9]\d{1000}$/);
+ expect(luhnCheck(number)).toBeTruthy();
+ });
+ });
- it('returns a specific and formally correct IBAN number', () => {
- const iban: string = faker.finance.iban(false, 'DE');
- const bban = iban.substring(4) + iban.substring(0, 4);
- const countryCode = iban.substring(0, 2);
- expect(countryCode).toBe('DE');
- expect(
- ibanLib.mod97(ibanLib.toDigitString(bban)),
- 'the result should be equal to 1'
- ).toStrictEqual(1);
- });
+ describe('creditCardCVV()', () => {
+ const cvv = faker.finance.creditCardCVV();
- it('throws an error if the passed country code is not supported', () => {
- expect(() => faker.finance.iban(false, 'AA')).toThrowError(
- Error('Country code AA not supported.')
- );
- });
- });
+ expect(typeof cvv).toBe('string');
+ expect(cvv).match(/\d{3}/);
+ expect(
+ cvv,
+ 'The length of the cvv should be 3 characters long'
+ ).toHaveLength(3);
+ });
- describe('litecoinAddress()', () => {
- const litecoinAddress = faker.finance.litecoinAddress();
- expect(typeof litecoinAddress).toBe('string');
- expect(litecoinAddress).match(/^[LM3][1-9a-km-zA-HJ-NP-Z]{25,32}$/);
- });
+ describe('ethereumAddress()', () => {
+ const ethereumAddress = faker.finance.ethereumAddress();
- describe('mask(length, parens, ellipsis)', () => {
- it('should set a default length', () => {
- const expected = 4; //default account mask length
- const mask = faker.finance.mask(null, false, false);
+ expect(typeof ethereumAddress).toBe('string');
+ expect(ethereumAddress).match(/^(0x)[0-9a-f]{40}$/);
+ });
- expect(
- mask,
- `The expected default mask length is ${expected} but it was ${mask.length}`
- ).toHaveLength(expected);
- });
+ describe('iban()', () => {
+ it('should return a random yet formally correct IBAN number', () => {
+ const iban: string = faker.finance.iban();
+ const bban = iban.substring(4) + iban.substring(0, 4);
- it('should set a specified length', () => {
- let expected = faker.datatype.number(20);
+ expect(
+ ibanLib.mod97(ibanLib.toDigitString(bban)),
+ 'the result should be equal to 1'
+ ).toStrictEqual(1);
+ });
- expected =
- expected === 0 || !expected || typeof expected == 'undefined'
- ? 4
- : expected;
+ it('should return a specific and formally correct IBAN number', () => {
+ const iban: string = faker.finance.iban(false, 'DE');
+ const bban = iban.substring(4) + iban.substring(0, 4);
+ const countryCode = iban.substring(0, 2);
- const mask = faker.finance.mask(expected, false, false); //the length of mask picks 4 if the random number generator picks 0
+ expect(countryCode).toBe('DE');
+ expect(
+ ibanLib.mod97(ibanLib.toDigitString(bban)),
+ 'the result should be equal to 1'
+ ).toStrictEqual(1);
+ });
- expect(
- mask,
- `The expected default mask length is ${expected} but it was ${mask.length}`
- ).toHaveLength(expected);
- });
- });
+ it('throws an error if the passed country code is not supported', () => {
+ expect(() => faker.finance.iban(false, 'AA')).toThrowError(
+ Error('Country code AA not supported.')
+ );
+ });
+ });
- describe('routingNumber()', () => {
- const routingNumber = faker.finance.routingNumber();
- expect(typeof routingNumber).toBe('string');
- });
+ describe('bic()', () => {
+ it('should return a random yet formally correct BIC number', () => {
+ const bic = faker.finance.bic();
+ const expr = new RegExp(
+ `^[A-Z]{4}(${ibanLib.iso3166.join(
+ '|'
+ )})[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?\$`,
+ 'i'
+ );
+
+ expect(typeof bic).toBe('string');
+ expect(bic).match(expr);
+ });
+ });
- describe('transactionDescription()', () => {
- const transactionDescription = faker.finance.transactionDescription();
- expect(typeof transactionDescription).toBe('string');
- });
+ describe('transactionDescription()', () => {
+ const transactionDescription = faker.finance.transactionDescription();
- describe('transactionType()', () => {
- const transactionType = faker.finance.transactionType();
- expect(typeof transactionType).toBe('string');
+ expect(typeof transactionDescription).toBe('string');
+ });
+ }
});
});