Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(finance): use fake patterns for transactionDescription #3202

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/definitions/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ export type FinanceDefinition = LocaleEntry<{
* Types of transactions (e.g. `deposit`).
*/
transaction_type: string[];

/**
* The pattern used to generate transaction descriptions.
*/
transaction_description_pattern: string[];
}>;
2 changes: 2 additions & 0 deletions src/locales/en/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type { FinanceDefinition } from '../../..';
import account_type from './account_type';
import credit_card from './credit_card';
import currency from './currency';
import transaction_description_pattern from './transaction_description_pattern';
import transaction_type from './transaction_type';

const finance: FinanceDefinition = {
account_type,
credit_card,
currency,
transaction_description_pattern,
transaction_type,
};

Expand Down
13 changes: 13 additions & 0 deletions src/locales/en/finance/transaction_description_pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default [
'A {{finance.transactionType}} for {{finance.currencyCode}} {{finance.amount}} was made at {{company.name}} via card ending ****{{string.numeric(4)}} on account ***{{string.numeric(4)}}.',
'A {{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} occurred at {{company.name}} using a card ending in ****{{string.numeric(4)}} for account ***{{string.numeric(4)}}.',
'Payment of {{finance.currencyCode}} {{finance.amount}} for {{finance.transactionType}} at {{company.name}}, processed with card ending ****{{string.numeric(4)}} linked to account ***{{string.numeric(4)}}.',
'Transaction alert: {{finance.transactionType}} at {{company.name}} using card ending ****{{string.numeric(4)}} for an amount of {{finance.currencyCode}} {{finance.amount}} on account ***{{string.numeric(4)}}.',
'You made a {{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} at {{company.name}} using card ending in ****{{string.numeric(4)}} from account ***{{string.numeric(4)}}.',
'Your {{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} at {{company.name}} was successful. Charged via card ****{{string.numeric(4)}} to account ***{{string.numeric(4)}}.',
'{{finance.transactionType}} at {{company.name}} with a card ending in ****{{string.numeric(4)}} for {{finance.currencyCode}} {{finance.amount}} from account ***{{string.numeric(4)}}.',
'{{finance.transactionType}} confirmed at {{company.name}} for {{finance.currencyCode}} {{finance.amount}}, card ending in ****{{string.numeric(4)}} associated with account ***{{string.numeric(4)}}.',
'{{finance.transactionType}} of {{finance.currencyCode}} {{finance.amount}} at {{company.name}} charged to account ending in {{string.numeric(4)}} using card ending in ****{{string.numeric(4)}}.',
'{{finance.transactionType}} processed at {{company.name}} for {{finance.currencyCode}} {{finance.amount}}, using card ending ****{{string.numeric(4)}}. Account: ***{{string.numeric(4)}}.',
'{{finance.transactionType}} transaction at {{company.name}} using card ending with ****{{string.numeric(4)}} for {{finance.currencyCode}} {{finance.amount}} in account ***{{string.numeric(4)}}.',
];
13 changes: 4 additions & 9 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,18 +969,13 @@ export class FinanceModule extends ModuleBase {
*
* @example
* faker.finance.transactionDescription()
* // 'invoice transaction at Kilback - Durgan using card ending with ************4316 for UAH 783.82 in account ***16168663'
* // 'payment transaction at Emard LLC using card ending with ****9187 for HNL 506.57 in account ***2584.'
*
* @since 5.1.0
*/
transactionDescription(): string {
const amount = this.amount();
const company = this.faker.company.name();
const transactionType = this.transactionType();
const account = this.accountNumber();
const card = this.creditCardNumber().replaceAll(/.(?=.{4})/g, '*');
const currency = this.currencyCode();

return `${transactionType} transaction at ${company} using card ending with ${card} for ${currency} ${amount} in account ***${account}`;
return this.faker.helpers.fake(
this.faker.definitions.finance.transaction_description_pattern
);
}
}
6 changes: 3 additions & 3 deletions test/modules/__snapshots__/finance.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports[`finance > 42 > pin > with length option 1`] = `"3975110867"`;

exports[`finance > 42 > routingNumber 1`] = `"397511082"`;

exports[`finance > 42 > transactionDescription 1`] = `"deposit transaction at Reynolds, Miller and Crist using card ending with ************4719 for LYD 374.54 in account ***08670982"`;
exports[`finance > 42 > transactionDescription 1`] = `"You made a withdrawal of SAR 598.66 at Crist - Beer using card ending in ****8670 from account ***9821."`;

exports[`finance > 42 > transactionType 1`] = `"invoice"`;

Expand Down Expand Up @@ -172,7 +172,7 @@ exports[`finance > 1211 > pin > with length option 1`] = `"9829667368"`;

exports[`finance > 1211 > routingNumber 1`] = `"982966738"`;

exports[`finance > 1211 > transactionDescription 1`] = `"payment transaction at Fahey, Zieme and Osinski using card ending with ***************2758 for HNL 928.52 in account ***73687684"`;
exports[`finance > 1211 > transactionDescription 1`] = `"withdrawal transaction at Zieme - Osinski using card ending with ****6736 for SZL 768.50 in account ***6848."`;

exports[`finance > 1211 > transactionType 1`] = `"withdrawal"`;

Expand Down Expand Up @@ -260,6 +260,6 @@ exports[`finance > 1337 > pin > with length option 1`] = `"2124352971"`;

exports[`finance > 1337 > routingNumber 1`] = `"212435298"`;

exports[`finance > 1337 > transactionDescription 1`] = `"invoice transaction at Gottlieb - Koelpin using card ending with *********6413 for JMD 262.02 in account ***52971361"`;
exports[`finance > 1337 > transactionDescription 1`] = `"Payment of CAD 278.12 for invoice at Leannon - Gibson, processed with card ending ****9713 linked to account ***6194."`;

exports[`finance > 1337 > transactionType 1`] = `"invoice"`;
Loading