Skip to content

Commit

Permalink
feat(locale): add unionpay credit card for zh_CN (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolPlayLin authored Sep 23, 2023
1 parent 48a7f54 commit 74eeccc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/locales/zh_CN/finance/credit_card/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/
import type { FinanceDefinition } from '../../../..';
import mastercard from './mastercard';
import unionpay from './unionpay';
import visa from './visa';

const credit_card: FinanceDefinition['credit_card'] = {
mastercard,
unionpay,
visa,
};

Expand Down
8 changes: 8 additions & 0 deletions src/locales/zh_CN/finance/credit_card/unionpay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
'62#############L',
'67#############L',
'81#############L',
'81##############L',
'81###############L',
'81################L',
];
11 changes: 10 additions & 1 deletion test/modules/finance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import isValidBtcAddress from 'validator/lib/isBtcAddress';
import isCreditCard from 'validator/lib/isCreditCard';
import { describe, expect, it } from 'vitest';
import { faker } from '../../src';
import { faker, fakerZH_CN } from '../../src';
import { FakerError } from '../../src/errors/faker-error';
import ibanLib from '../../src/modules/finance/iban';
import { luhnCheck } from '../../src/modules/helpers/luhn-check';
Expand Down Expand Up @@ -476,6 +477,14 @@ describe('finance', () => {
expect(maestro).toSatisfy(luhnCheck);
});

it('should generate a valid union pay credit card', () => {
const actual = fakerZH_CN.finance.creditCardNumber('unionpay');
expect(actual).toSatisfy(luhnCheck);
expect(actual).toSatisfy((value) =>
isCreditCard(value as string, { provider: 'unionpay' })
);
});

it('should return custom formatted strings', () => {
let number = faker.finance.creditCardNumber('###-###-##L');
expect(number).toMatch(/^\d{3}\-\d{3}\-\d{3}$/);
Expand Down

0 comments on commit 74eeccc

Please sign in to comment.