-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
fix(finance): routingNumber now uses real FederalReserveRoutingSymbol from lookup table. #3429
base: next
Are you sure you want to change the base?
Conversation
…). Added some conditions to random-seeded finance.routingNumber test. Updated finance test snapshot.
… directive snuck into the index.ts file.
✅ Deploy Preview for fakerjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #3429 +/- ##
========================================
Coverage 99.97% 99.97%
========================================
Files 2811 2813 +2
Lines 216972 217149 +177
Branches 944 944
========================================
+ Hits 216917 217094 +177
Misses 55 55
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a little more detail to the method description
e.g.
"Generates a random routing number."
=>
"Generates a random [ABA routing number](https://en.wikipedia.org/wiki/ABA_routing_transit_number)"
…age for ABA Routing Number. Updated the example string given to reflect the new changes.
Done. I used one of the routing numbers from the test snapshot for the example string. |
Also, I forgot to mention... I couldn't figure out how to link the original issue to this PR. Sorry I am a bit new to contributing to public github repos. |
Also, as I'm sure you've noticed, I skipped any form of testing whether the 2nd group of 2 digits at indexes 2-3 actually matched up with one of the numbers listed in the base finance locale. Of course were I to do that, what I'd really be doing is simply checking if Edit: On a site note, it was interesting to find out that validate.js's Edit 2: After looking at the validator.js source again, I had missed this regex at the top:
Which is checking (though not obviously, of course) that the federal reserve district is correct. Quoted from the wikipedia page on ABA routing numbers:
So that regex is effectively trying to be as exhaustive as possible, almost like an official spec would, except it's a little bizarre for two reasons: One is that it is allowing 000000000, which passes even the check digit validation and is definitely not a valid routing number. So tl;dr the call to |
const routingNumber = faker.finance.routingNumber(); | ||
|
||
const firstTwoDigits = routingNumber.substring(0, 2); | ||
const federalReserveDistrict = Number.parseInt(firstTwoDigits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these into the the it()
test blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I think I did it that way for DRY purposes, as you'd need to re-construct routingNumber
(or any other variable used in multiple it()
blocks, but that's the only one this applies to here) each time you needed to reference it inside of the it()
block, but if that's what you want, that's fine. I don't quite understand what's wrong with doing it the way I did it, but that's fine. If you care to explain I'd be happy to know though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vitest uses callbacks (() => {}
) to run the tests. And to re-run them.
If the values are declared outside the callback then they wont change for subsequent executions. We run these tests multiple times to ensure they dont pass by chance (or at least reduce the probability).
faker/test/modules/finance.spec.ts
Lines 107 to 109 in f591459
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( | |
'random seeded tests for seed %i', | |
() => { |
it('should return a string', () => { | ||
expect(routingNumber).toBeTypeOf('string'); | ||
}); | ||
|
||
it('should pass check digit validation', () => { | ||
expect(routingNumber).toSatisfy(isAbaRouting); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO these two test cases should be joined into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see from validator's source that it is already asserting that it is a string. Does that make the first check completely unnecessary? The one argument I can see for saying NO to that is that that would leave the validity of faker.js's tests dependent upon the implementation details of validator.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string check makes the result in the tests easier to grasp even if you dont read the jsdocs of either method.
The timeouts happen randomly unfortunately. Even if we increase it to 30s. As for the pnpm update, you might have to update node to the latest (LTS) version. That solved it for me. |
Fixes #3290
finance.routingNumber is now comprised as follows:
Digits 0-3 = Pulled from locales/base/finance/federal_reserve_routing_symbol.ts
Digits 4-7 = Random
Digit 8 = Check digit. Calculated from the previous 8 digits as before.
Added more test conditions to the randomly-seeded finance.routingNumber test.