diff options
| author | Shinigami <[email protected]> | 2024-03-10 00:57:03 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-09 23:57:03 +0000 |
| commit | a536a9d79f410986e6bd6dc1bc4a72252a0cc8d9 (patch) | |
| tree | 08d250b84340b02be90b9300d8306dbe9c19b35f /test/modules | |
| parent | db7aaa0801f9c71812debac4dcd507e103bec15a (diff) | |
| download | faker-a536a9d79f410986e6bd6dc1bc4a72252a0cc8d9.tar.xz faker-a536a9d79f410986e6bd6dc1bc4a72252a0cc8d9.zip | |
refactor(finance)!: remove v8 deprecated finance methods (#2727)
Diffstat (limited to 'test/modules')
| -rw-r--r-- | test/modules/__snapshots__/finance.spec.ts.snap | 78 | ||||
| -rw-r--r-- | test/modules/finance-iban.spec.ts | 35 | ||||
| -rw-r--r-- | test/modules/finance.spec.ts | 134 |
3 files changed, 61 insertions, 186 deletions
diff --git a/test/modules/__snapshots__/finance.spec.ts.snap b/test/modules/__snapshots__/finance.spec.ts.snap index 146db5d6..30e1f66a 100644 --- a/test/modules/__snapshots__/finance.spec.ts.snap +++ b/test/modules/__snapshots__/finance.spec.ts.snap @@ -1,9 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`finance > 42 > account > noArgs 1`] = `"39751108"`; - -exports[`finance > 42 > account > with length 1`] = `"3975110867"`; - exports[`finance > 42 > accountName 1`] = `"Money Market Account"`; exports[`finance > 42 > accountNumber > noArgs 1`] = `"39751108"`; @@ -14,18 +10,10 @@ exports[`finance > 42 > accountNumber > with length option 1`] = `"3975110867"`; exports[`finance > 42 > amount > noArgs 1`] = `"374.54"`; -exports[`finance > 42 > amount > with leagcy dec 1`] = `"374.54012"`; - -exports[`finance > 42 > amount > with leagcy max 1`] = `"18.73"`; - -exports[`finance > 42 > amount > with min 1`] = `"380.79"`; - exports[`finance > 42 > amount > with min and max option 1`] = `"24.98"`; exports[`finance > 42 > amount > with min option 1`] = `"380.79"`; -exports[`finance > 42 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$24.98160"`; - exports[`finance > 42 > amount > with min, max and dec option 1`] = `"24.98160"`; exports[`finance > 42 > amount > with min, max, dec and symbol option 1`] = `"#24.98160"`; @@ -68,26 +56,12 @@ exports[`finance > 42 > ethereumAddress 1`] = `"0x8ead331ddf0fc4446b96d368ab4bd1 exports[`finance > 42 > iban > noArgs 1`] = `"GT69T10P0V1346241560ZH610G35"`; -exports[`finance > 42 > iban > with formatted 1`] = `"GT69 T10P 0V13 4624 1560 ZH61 0G35"`; - -exports[`finance > 42 > iban > with formatted and countryCode 1`] = `"DE69 9500 1670 8002 5210 05"`; - exports[`finance > 42 > iban > with formatted and countryCode option 1`] = `"DE69 9500 1670 8002 5210 05"`; exports[`finance > 42 > iban > with formatted option 1`] = `"GT69 T10P 0V13 4624 1560 ZH61 0G35"`; exports[`finance > 42 > litecoinAddress 1`] = `"3JAaa4SAH2YQdbbiwrhB9hnsMcvA"`; -exports[`finance > 42 > mask > noArgs 1`] = `"(...3975)"`; - -exports[`finance > 42 > mask > with ellipsis 1`] = `"(...3975)"`; - -exports[`finance > 42 > mask > with length 1`] = `"(...39751)"`; - -exports[`finance > 42 > mask > with length, parenthesis and ellipsis 1`] = `"(...39751)"`; - -exports[`finance > 42 > mask > with parenthesis 1`] = `"(...3975)"`; - exports[`finance > 42 > maskedNumber > noArgs 1`] = `"(...3975)"`; exports[`finance > 42 > maskedNumber > with length 1`] = `"(...39751)"`; @@ -110,10 +84,6 @@ exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Re exports[`finance > 42 > transactionType 1`] = `"withdrawal"`; -exports[`finance > 1211 > account > noArgs 1`] = `"98296673"`; - -exports[`finance > 1211 > account > with length 1`] = `"9829667368"`; - exports[`finance > 1211 > accountName 1`] = `"Personal Loan Account"`; exports[`finance > 1211 > accountNumber > noArgs 1`] = `"98296673"`; @@ -124,18 +94,10 @@ exports[`finance > 1211 > accountNumber > with length option 1`] = `"9829667368" exports[`finance > 1211 > amount > noArgs 1`] = `"928.52"`; -exports[`finance > 1211 > amount > with leagcy dec 1`] = `"928.52016"`; - -exports[`finance > 1211 > amount > with leagcy max 1`] = `"46.43"`; - -exports[`finance > 1211 > amount > with min 1`] = `"929.24"`; - exports[`finance > 1211 > amount > with min and max option 1`] = `"47.15"`; exports[`finance > 1211 > amount > with min option 1`] = `"929.24"`; -exports[`finance > 1211 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$47.14081"`; - exports[`finance > 1211 > amount > with min, max and dec option 1`] = `"47.14081"`; exports[`finance > 1211 > amount > with min, max, dec and symbol option 1`] = `"#47.14081"`; @@ -178,26 +140,12 @@ exports[`finance > 1211 > ethereumAddress 1`] = `"0xed4fefa7fbaec9dc4c48fa8ebf46 exports[`finance > 1211 > iban > noArgs 1`] = `"TN8326736788219352058231"`; -exports[`finance > 1211 > iban > with formatted 1`] = `"TN83 2673 6788 2193 5205 8231"`; - -exports[`finance > 1211 > iban > with formatted and countryCode 1`] = `"DE13 8077 6768 8219 3520 53"`; - exports[`finance > 1211 > iban > with formatted and countryCode option 1`] = `"DE13 8077 6768 8219 3520 53"`; exports[`finance > 1211 > iban > with formatted option 1`] = `"TN83 2673 6788 2193 5205 8231"`; exports[`finance > 1211 > litecoinAddress 1`] = `"3eZEFLmGPLEQrSRdAcnZLoWwYeiHwmRog"`; -exports[`finance > 1211 > mask > noArgs 1`] = `"(...9829)"`; - -exports[`finance > 1211 > mask > with ellipsis 1`] = `"(...9829)"`; - -exports[`finance > 1211 > mask > with length 1`] = `"(...98296)"`; - -exports[`finance > 1211 > mask > with length, parenthesis and ellipsis 1`] = `"(...98296)"`; - -exports[`finance > 1211 > mask > with parenthesis 1`] = `"(...9829)"`; - exports[`finance > 1211 > maskedNumber > noArgs 1`] = `"(...9829)"`; exports[`finance > 1211 > maskedNumber > with length 1`] = `"(...98296)"`; @@ -220,10 +168,6 @@ exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at exports[`finance > 1211 > transactionType 1`] = `"invoice"`; -exports[`finance > 1337 > account > noArgs 1`] = `"21243529"`; - -exports[`finance > 1337 > account > with length 1`] = `"2124352971"`; - exports[`finance > 1337 > accountName 1`] = `"Money Market Account"`; exports[`finance > 1337 > accountNumber > noArgs 1`] = `"21243529"`; @@ -234,18 +178,10 @@ exports[`finance > 1337 > accountNumber > with length option 1`] = `"2124352971" exports[`finance > 1337 > amount > noArgs 1`] = `"262.02"`; -exports[`finance > 1337 > amount > with leagcy dec 1`] = `"262.02467"`; - -exports[`finance > 1337 > amount > with leagcy max 1`] = `"13.10"`; - -exports[`finance > 1337 > amount > with min 1`] = `"269.40"`; - exports[`finance > 1337 > amount > with min and max option 1`] = `"20.48"`; exports[`finance > 1337 > amount > with min option 1`] = `"269.40"`; -exports[`finance > 1337 > amount > with min, leagcy max, leagcy dec and leagcy symbol 1`] = `"$20.48098"`; - exports[`finance > 1337 > amount > with min, max and dec option 1`] = `"20.48098"`; exports[`finance > 1337 > amount > with min, max, dec and symbol option 1`] = `"#20.48098"`; @@ -288,26 +224,12 @@ exports[`finance > 1337 > ethereumAddress 1`] = `"0x536a7b5fa28d2f9bb79ca46ea394 exports[`finance > 1337 > iban > noArgs 1`] = `"FO2200532700604734"`; -exports[`finance > 1337 > iban > with formatted 1`] = `"FO22 0053 2700 6047 34"`; - -exports[`finance > 1337 > iban > with formatted and countryCode 1`] = `"DE04 0033 2713 1474 7007 41"`; - exports[`finance > 1337 > iban > with formatted and countryCode option 1`] = `"DE04 0033 2713 1474 7007 41"`; exports[`finance > 1337 > iban > with formatted option 1`] = `"FO22 0053 2700 6047 34"`; exports[`finance > 1337 > litecoinAddress 1`] = `"LhsjwgYJ7oC8ZrMNmqzLbhEubpcw"`; -exports[`finance > 1337 > mask > noArgs 1`] = `"(...2124)"`; - -exports[`finance > 1337 > mask > with ellipsis 1`] = `"(...2124)"`; - -exports[`finance > 1337 > mask > with length 1`] = `"(...21243)"`; - -exports[`finance > 1337 > mask > with length, parenthesis and ellipsis 1`] = `"(...21243)"`; - -exports[`finance > 1337 > mask > with parenthesis 1`] = `"(...2124)"`; - exports[`finance > 1337 > maskedNumber > noArgs 1`] = `"(...2124)"`; exports[`finance > 1337 > maskedNumber > with length 1`] = `"(...21243)"`; diff --git a/test/modules/finance-iban.spec.ts b/test/modules/finance-iban.spec.ts index 4d801aa5..f699ada4 100644 --- a/test/modules/finance-iban.spec.ts +++ b/test/modules/finance-iban.spec.ts @@ -11,7 +11,10 @@ describe('finance_iban', () => { describe('generic IBAN country checks', () => { it.each(ibanLib.formats.map((entry) => entry.country))('%s', (country) => { expect(country).toMatch(/^[A-Z]{2}$/); - const actual = faker.finance.iban(true, country); + const actual = faker.finance.iban({ + formatted: true, + countryCode: country, + }); expect(actual).toMatch(new RegExp(`^${country}`)); expect(actual).toSatisfy(validator.isIBAN); @@ -33,7 +36,10 @@ describe('finance_iban', () => { // example IBAN GE29 NB00 0000 0101 9049 17 - const iban = faker.finance.iban(false, 'GE'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'GE', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -93,7 +99,10 @@ describe('finance_iban', () => { // Account Code 16 digits // Total Length 24 chars - const iban = faker.finance.iban(false, 'PK'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'PK', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -159,7 +168,10 @@ describe('finance_iban', () => { // Chiffre d'indicatif national 0 // Numéro de compte bancaire 0519786457841326 - const iban = faker.finance.iban(false, 'TR'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'TR', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -229,7 +241,10 @@ describe('finance_iban', () => { // example IBAN AZ21 NABZ 0000 0000 1370 1000 1944 - const iban = faker.finance.iban(false, 'AZ'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'AZ', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -288,7 +303,10 @@ describe('finance_iban', () => { // example IBAN CR05 0152 0200 1026 2840 66 - const iban = faker.finance.iban(false, 'CR'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'CR', + }); expect(iban).toSatisfy(validator.isIBAN); @@ -336,7 +354,10 @@ describe('finance_iban', () => { // National check digit 1 digit // Bank account number 16 digit - const iban = faker.finance.iban(false, 'AL'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'AL', + }); const ibanFormated = prettyPrintIban(iban); expect(iban).toSatisfy(validator.isIBAN); diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index db60a9b3..0b9a4d6c 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -28,10 +28,6 @@ describe('finance', () => { 'transactionDescription' ); - t.describe('account', (t) => { - t.it('noArgs').it('with length', 10); - }); - t.describe('accountNumber', (t) => { t.it('noArgs') .it('with length', 10) @@ -61,17 +57,7 @@ describe('finance', () => { dec: 5, symbol: '#', autoFormat: false, - }) - .it('with min', 10) - .it('with leagcy max', undefined, 50) - .it('with leagcy dec', undefined, undefined, 5) - .it( - 'with min, leagcy max, leagcy dec and leagcy symbol', - 10, - 50, - 5, - '$' - ); + }); }); t.describe('bic', (t) => { @@ -84,9 +70,7 @@ describe('finance', () => { .it('with formatted and countryCode option', { formatted: true, countryCode: 'DE', - }) - .it('with formatted', true) - .it('with formatted and countryCode', true, 'DE'); + }); }); t.describe('creditCardNumber', (t) => { @@ -96,14 +80,6 @@ describe('finance', () => { .it('with issuer option mastercard', { issuer: 'mastercard' }); }); - t.describe('mask', (t) => { - t.it('noArgs') - .it('with length', 5) - .it('with parenthesis', undefined, true) - .it('with ellipsis', undefined, undefined, true) - .it('with length, parenthesis and ellipsis', 5, true, true); - }); - t.describe('maskedNumber', (t) => { t.it('noArgs') .it('with length', 5) @@ -120,28 +96,6 @@ describe('finance', () => { describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( 'random seeded tests for seed %i', () => { - describe('account()', () => { - it('should supply a default length', () => { - const accountNumber = faker.finance.account(); - - expect(accountNumber).toBeTruthy(); - expect( - accountNumber, - 'The length of the account number should be 8 characters long' - ).toHaveLength(8); - }); - - it('should have same length as given length number', () => { - const accountNumber = faker.finance.account(16); - - expect(accountNumber).toBeTruthy(); - expect( - 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(); @@ -191,31 +145,6 @@ describe('finance', () => { }); }); - describe('mask()', () => { - it('should set a default length', () => { - const expected = 4; // default account mask length - const mask = faker.finance.mask(undefined, false, false); - - expect( - mask, - `The expected default mask length is ${expected} but it was ${mask.length}` - ).toHaveLength(expected); - }); - - it('should set a specified length', () => { - let expected = faker.number.int(20); - - expected = expected || 4; - - const mask = faker.finance.mask(expected, false, false); // the length of mask picks 4 if the random number generator picks 0 - - expect( - mask, - `The expected default mask length is ${expected} but it was ${mask.length}` - ).toHaveLength(expected); - }); - }); - describe('maskedNumber()', () => { it('should return contain parenthesis, ellipsis and have a length of 4 by default', () => { const actual = faker.finance.maskedNumber(); @@ -264,15 +193,6 @@ describe('finance', () => { expect(+amount).toBeLessThanOrEqual(1000); }); - it('should use the default decimal location when not passing arguments', () => { - let amount = faker.finance.amount(); - - amount = faker.finance.amount(100, 100, 1); - - expect(amount).toBeTruthy(); - expect(amount).toBe('100.0'); - }); - //TODO: add support for more currency and decimal options it('should not include a currency symbol by default', () => { const amount = faker.finance.amount(); @@ -286,7 +206,7 @@ describe('finance', () => { }); it('should handle negative amounts', () => { - const amount = faker.finance.amount(-200, -1); + const amount = faker.finance.amount({ min: -200, max: -1 }); expect(amount).toBeTruthy(); expect(amount).toBeTypeOf('string'); @@ -294,8 +214,16 @@ describe('finance', () => { expect(+amount).toBeGreaterThanOrEqual(-200); }); + it('should use the default dec', () => { + const amount = faker.finance.amount({ min: 100, max: 100 }); + + expect(amount).toBeTruthy(); + expect(amount).toBeTypeOf('string'); + expect(amount).toBe('100.00'); + }); + it('should handle argument dec', () => { - const amount = faker.finance.amount(100, 100, 1); + const amount = faker.finance.amount({ min: 100, max: 100, dec: 1 }); expect(amount).toBeTruthy(); expect(amount).toBeTypeOf('string'); @@ -303,7 +231,7 @@ describe('finance', () => { }); it('should handle argument dec = 0', () => { - const amount = faker.finance.amount(100, 100, 0); + const amount = faker.finance.amount({ min: 100, max: 100, dec: 0 }); expect(amount).toBeTruthy(); expect(amount).toBeTypeOf('string'); @@ -314,13 +242,12 @@ describe('finance', () => { 'should return unformatted if autoformat is %s', (autoFormat) => { const number = 6000; - const amount = faker.finance.amount( - number, - number, - 0, - undefined, - autoFormat - ); + const amount = faker.finance.amount({ + min: number, + max: number, + dec: 0, + autoFormat, + }); expect(amount).toBe(number.toString()); } @@ -333,13 +260,12 @@ describe('finance', () => { minimumFractionDigits: decimalPlaces, }); - const amount = faker.finance.amount( - number, - number, - decimalPlaces, - undefined, - true - ); + const amount = faker.finance.amount({ + min: number, + max: number, + dec: decimalPlaces, + autoFormat: true, + }); expect(amount).toStrictEqual(expected); }); @@ -562,7 +488,10 @@ describe('finance', () => { }); it('should return a specific and formally correct IBAN number', () => { - const iban = faker.finance.iban(false, 'DE'); + const iban = faker.finance.iban({ + formatted: false, + countryCode: 'DE', + }); const bban = iban.substring(4) + iban.substring(0, 4); const countryCode = iban.substring(0, 2); @@ -577,7 +506,10 @@ describe('finance', () => { 'throws an error for unsupported country code "%s"', (unsupportedCountryCode) => expect(() => - faker.finance.iban(false, unsupportedCountryCode) + faker.finance.iban({ + formatted: false, + countryCode: unsupportedCountryCode, + }) ).toThrow( new FakerError( `Country code ${unsupportedCountryCode} not supported.` |
