Skip to content

Commit e190df8

Browse files
committed
test: add finance.pin() tests
1 parent 9ee0924 commit e190df8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test/finance.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const seedRuns = [
2020
litecoinAddress: '3XbJMAAara64sSkA9HD24YHQWd1b',
2121
creditCardNumber: '3581-7755-1410-0486',
2222
creditCardCVV: '379',
23+
pin: '3791',
2324
ethereumAddress: '0x8be4abdd39321ad7d3fe01ffce404f4d6db0906b',
2425
iban: 'GT30Y75110867098F1E3542612J4',
2526
bic: 'UYEOSCP1514',
@@ -43,6 +44,7 @@ const seedRuns = [
4344
litecoinAddress: 'Madhxs2jewAgkYgJi7No6Cn8JZar',
4445
creditCardNumber: '6011-6212-2540-3255-2392',
4546
creditCardCVV: '251',
47+
pin: '2512',
4648
ethereumAddress: '0x5c346ba075bd57f5a62b82d72af39cbbb07a98cb',
4749
iban: 'FO7710540350900318',
4850
bic: 'OEFELYL1032',
@@ -66,6 +68,7 @@ const seedRuns = [
6668
litecoinAddress: 'MTMe8Z3EaFdLqmaGKP1LEEJQVriSZRZds',
6769
creditCardNumber: '4872190616276',
6870
creditCardCVV: '948',
71+
pin: '9487',
6972
ethereumAddress: '0xeadb42f0e3f4a973fab0aeefce96dfcf49cd438d',
7073
iban: 'TN0382001124170679299069',
7174
bic: 'LXUEBTZ1',
@@ -89,6 +92,7 @@ const functionNames = [
8992
'litecoinAddress',
9093
'creditCardNumber',
9194
'creditCardCVV',
95+
'pin',
9296
'ethereumAddress',
9397
'iban',
9498
'bic',
@@ -452,6 +456,39 @@ describe('finance', () => {
452456
});
453457
});
454458

459+
describe('pin()', () => {
460+
it('should return a string', () => {
461+
const pin = faker.finance.pin();
462+
expect(pin).toBeTypeOf('string');
463+
});
464+
465+
it('should have all characters be a digit', () => {
466+
const pin = faker.finance.pin();
467+
expect(pin).toMatch(/^[0-9]+$/);
468+
});
469+
470+
it('should default to 4 digits', () => {
471+
const pin = faker.finance.pin();
472+
expect(pin).toHaveLength(4);
473+
});
474+
475+
it('should return a pin with the specified length', () => {
476+
let pin = faker.finance.pin(1);
477+
expect(pin).toHaveLength(1);
478+
pin = faker.finance.pin(5);
479+
expect(pin).toHaveLength(5);
480+
pin = faker.finance.pin(13);
481+
expect(pin).toHaveLength(13);
482+
pin = faker.finance.pin(57);
483+
expect(pin).toHaveLength(57);
484+
});
485+
486+
it('should not crash when digits parameter is 0', () => {
487+
const pin = faker.finance.pin(0);
488+
expect(pin).toHaveLength(0);
489+
});
490+
});
491+
455492
describe('ethereumAddress()', () => {
456493
it('should return a valid ethereum address', () => {
457494
const ethereumAddress = faker.finance.ethereumAddress();

0 commit comments

Comments
 (0)