Skip to content

Commit 74eeccc

Browse files
authored
feat(locale): add unionpay credit card for zh_CN (#2338)
1 parent 48a7f54 commit 74eeccc

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/locales/zh_CN/finance/credit_card/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*/
55
import type { FinanceDefinition } from '../../../..';
66
import mastercard from './mastercard';
7+
import unionpay from './unionpay';
78
import visa from './visa';
89

910
const credit_card: FinanceDefinition['credit_card'] = {
1011
mastercard,
12+
unionpay,
1113
visa,
1214
};
1315

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default [
2+
'62#############L',
3+
'67#############L',
4+
'81#############L',
5+
'81##############L',
6+
'81###############L',
7+
'81################L',
8+
];

test/modules/finance.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import isValidBtcAddress from 'validator/lib/isBtcAddress';
2+
import isCreditCard from 'validator/lib/isCreditCard';
23
import { describe, expect, it } from 'vitest';
3-
import { faker } from '../../src';
4+
import { faker, fakerZH_CN } from '../../src';
45
import { FakerError } from '../../src/errors/faker-error';
56
import ibanLib from '../../src/modules/finance/iban';
67
import { luhnCheck } from '../../src/modules/helpers/luhn-check';
@@ -476,6 +477,14 @@ describe('finance', () => {
476477
expect(maestro).toSatisfy(luhnCheck);
477478
});
478479

480+
it('should generate a valid union pay credit card', () => {
481+
const actual = fakerZH_CN.finance.creditCardNumber('unionpay');
482+
expect(actual).toSatisfy(luhnCheck);
483+
expect(actual).toSatisfy((value) =>
484+
isCreditCard(value as string, { provider: 'unionpay' })
485+
);
486+
});
487+
479488
it('should return custom formatted strings', () => {
480489
let number = faker.finance.creditCardNumber('###-###-##L');
481490
expect(number).toMatch(/^\d{3}\-\d{3}\-\d{3}$/);

0 commit comments

Comments
 (0)