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

refactor(finance): use fake patterns in transactionDescription #3202

Draft
wants to merge 10 commits into
base: next
Choose a base branch
from

Conversation

ST-DDT
Copy link
Member

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

The transaction description method is very limited in it's applications.

The method generates multiple values from the finance module and masks and concats them together.

invoice transaction at Kilback - Durgan using card ending with ***(...4316) for UAH 783.82 in account ***16168663

I would argue, that the textual representation of these information is an implementation detail of the UI that will show it.
e.g. it would likely be displayed as

invoice transaction at Kilback - Durgan using card ending with ***(...4316) for UAH 783.82 in account ***16168663

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

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 338c778
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/6748bac3920206000861c80d
😎 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.95%. Comparing base (5d5fe30) to head (338c778).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3202      +/-   ##
==========================================
- Coverage   99.97%   99.95%   -0.02%     
==========================================
  Files        2806     2806              
  Lines      217140   217146       +6     
  Branches      982      975       -7     
==========================================
- Hits       217075   217053      -22     
- Misses         65       93      +28     
Files with missing lines Coverage Δ
src/modules/finance/index.ts 100.00% <100.00%> (ø)

... and 1 file 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs deprecation A deprecation was made in the PR has workaround Workaround provided or linked 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