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

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Oct 20, 2024

This PR changes the faker.finance.transactionDescription() method to use fake patterns instead of a hard coded string.

Popularity-Data from #3215

  • faker.finance.transactionDescription: 20

@ST-DDT ST-DDT added p: 1-normal Nothing urgent c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs m: finance Something is referring to the finance module deprecation A deprecation was made in the PR labels Oct 20, 2024
@ST-DDT ST-DDT added this to the v9.x milestone Oct 20, 2024
@ST-DDT ST-DDT requested review from a team October 20, 2024 17:37
@ST-DDT ST-DDT self-assigned this Oct 20, 2024
Copy link

netlify bot commented Oct 20, 2024

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit ad17f71
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/6759e8678a987c0008667ee8
😎 Deploy Preview https://deploy-preview-3202.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.96%. Comparing base (4b4bac3) to head (ad17f71).
Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #3202   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files        2806     2807    +1     
  Lines      217076   217087   +11     
  Branches      964      966    +2     
=======================================
+ Hits       216997   217008   +11     
  Misses         79       79           
Files with missing lines Coverage Δ
src/definitions/finance.ts 100.00% <ø> (ø)
src/locales/en/finance/index.ts 100.00% <100.00%> (ø)
...ales/en/finance/transaction_description_pattern.ts 100.00% <100.00%> (ø)
src/modules/finance/index.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@ST-DDT
Copy link
Member Author

ST-DDT commented Oct 20, 2024

If you still need the method, please inline/copy the implementation:

transactionDescription(): string {
    const amount = faker.finance.amount();
    const company = faker.company.name();
    const transactionType = faker.finance.transactionType();
    const account = faker.finance.accountNumber();
    const card = faker.finance.creditCardNumber().replaceAll(/(?<=.{4}).(?=.{2})/g, '*');
    const currency = faker.finance.currencyCode();

    return `${transactionType} transaction at ${company} using card ending with ***${card} for ${currency} ${amount} in account ***${account}`;
  }

@ST-DDT ST-DDT added the has workaround Workaround provided or linked label Oct 20, 2024
Shinigami92
Shinigami92 previously approved these changes Oct 22, 2024
@ST-DDT ST-DDT requested a review from a team October 22, 2024 18:30
src/modules/finance/index.ts Outdated Show resolved Hide resolved
@xDivisionByZerox
Copy link
Member

Popularity-Data from #3215

  • faker.finance.transactionDescription: 20

A quick GH search says otherwise 🤔
I have to admit that some of the references are pretty plain and wouldn't suffer from the method going exstinct.

I would consider this a method generating a complex object although it is a string. Which makes the method our of scope for Faker.

I actually kind of agree with you here. BUT:

  1. we had no complains about the methods implementation so far (as far as i know)
  2. we did a lot of restructuring and deprecating during v8.0 which did upset some people as we know (2 million people are still on latest v7)

Having this method in our codebase doesn't cause a big enought pain point to call for emidiate action in my opinion.

@matthewmayer
Copy link
Contributor

I tend to agree this doesnt cause any harm and should be left alone. Perhaps we could add a note this is discouraged for new code without formally deprecating it.

@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 25, 2024

I tend to agree this doesnt cause any harm

The method only produces English output and isn't usable outside of the English locale.
Worse for non English locales this produces mixed language results.

fakerZH_CN.finance.transactionDescription()
"支付 transaction at 诸州市智杰网络科技有限公司 using card ending with ***(...5783) for GBP 680.89 in account ***18156282"

Note: I'm not against soft-deprecating this method, I just wanted to raise awareness of this fact.


If we go for soft-deprecation, how about a text like this:

Soft-Deprecated: New code should not use this method as it generates a text that has no real-world use other than being an English text.
If you need just a text, please consider using the lorem module or faker.food.description()
The Faker team considers this method out of scope for the library as it returns a dynamic complex object disguised as a string.
Since the method doesn't cause any harm, we will not remove it yet.

@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Nov 25, 2024
@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 25, 2024

Or alternatively, we convert it to a proper localized method.

@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 28, 2024

Team Decision

  • We will not deprecate this method.
  • We will refactor the current implementation to use localized fake patterns instead of a hard-coded parameterized English string.

@ST-DDT ST-DDT changed the title refactor(finance): deprecate transactionDescription for removal refactor(finance): use fake patterns in transactionDescription Nov 28, 2024
@ST-DDT ST-DDT removed the s: needs decision Needs team/maintainer decision label Nov 28, 2024
@ST-DDT ST-DDT modified the milestones: v9.x, vAnytime Nov 28, 2024
@ST-DDT ST-DDT marked this pull request as draft November 28, 2024 20:10
@ST-DDT ST-DDT force-pushed the deprecate/finance/transactionDescription branch from 338c778 to c7b2116 Compare December 2, 2024 22:38
@ST-DDT ST-DDT force-pushed the deprecate/finance/transactionDescription branch from c7b2116 to 4daf6c6 Compare December 2, 2024 22:43
@ST-DDT ST-DDT force-pushed the deprecate/finance/transactionDescription branch from 4daf6c6 to f95c4b4 Compare December 2, 2024 22:49
@ST-DDT ST-DDT changed the title refactor(finance): use fake patterns in transactionDescription feat(finance): use fake patterns for transactionDescription Dec 2, 2024
@ST-DDT ST-DDT added c: feature Request for new feature and removed c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs has workaround Workaround provided or linked deprecation A deprecation was made in the PR labels Dec 2, 2024
@ST-DDT ST-DDT marked this pull request as ready for review December 2, 2024 22:55
@ST-DDT
Copy link
Member Author

ST-DDT commented Dec 2, 2024

Ready for review.

@ST-DDT ST-DDT requested a review from a team December 3, 2024 10:58
@ST-DDT ST-DDT merged commit 5ec4a6c into next Dec 11, 2024
23 checks passed
@ST-DDT ST-DDT deleted the deprecate/finance/transactionDescription branch December 11, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature m: finance Something is referring to the finance module p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants