From 74eecccd3af702d8a1d8072f94032ccb54293cb1 Mon Sep 17 00:00:00 2001 From: CoolPlayLin Date: Sun, 24 Sep 2023 01:45:34 +0800 Subject: [PATCH] feat(locale): add unionpay credit card for zh_CN (#2338) --- src/locales/zh_CN/finance/credit_card/index.ts | 2 ++ src/locales/zh_CN/finance/credit_card/unionpay.ts | 8 ++++++++ test/modules/finance.spec.ts | 11 ++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/locales/zh_CN/finance/credit_card/unionpay.ts diff --git a/src/locales/zh_CN/finance/credit_card/index.ts b/src/locales/zh_CN/finance/credit_card/index.ts index 043cd15494a..83f241e0909 100644 --- a/src/locales/zh_CN/finance/credit_card/index.ts +++ b/src/locales/zh_CN/finance/credit_card/index.ts @@ -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, }; diff --git a/src/locales/zh_CN/finance/credit_card/unionpay.ts b/src/locales/zh_CN/finance/credit_card/unionpay.ts new file mode 100644 index 00000000000..b6bc8e70978 --- /dev/null +++ b/src/locales/zh_CN/finance/credit_card/unionpay.ts @@ -0,0 +1,8 @@ +export default [ + '62#############L', + '67#############L', + '81#############L', + '81##############L', + '81###############L', + '81################L', +]; diff --git a/test/modules/finance.spec.ts b/test/modules/finance.spec.ts index a783f0731f5..d5de18178ab 100644 --- a/test/modules/finance.spec.ts +++ b/test/modules/finance.spec.ts @@ -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'; @@ -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}$/);