-
Notifications
You must be signed in to change notification settings - Fork 25
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
[#168453950] Adult check at login if dateOfBirth is provided #575
base: master
Are you sure you want to change the base?
Conversation
Affected stories
Generated by 🚫 dangerJS |
Codecov Report
@@ Coverage Diff @@
## master #575 +/- ##
========================================
+ Coverage 83.88% 84% +0.11%
========================================
Files 49 50 +1
Lines 1489 1500 +11
Branches 249 250 +1
========================================
+ Hits 1249 1260 +11
Misses 231 231
Partials 9 9
Continue to review full report at Codecov.
|
src/utils/date.ts
Outdated
year: t.string | ||
}); | ||
|
||
export const isAdult = (dateOfBirth: string): boolean => { |
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.
I'd refactor this method to take currentDate as input. This will simplify tests of isAdult() that should be deterministic and not use new Date()
(tests should use hardcoded dates)
something like --> const isOlderThan = (years: number) => (dateOfBirth: Date, when: Date) => { ... }
moreover I'd move the date parsing into the caller and, if we already include something like date-fns (or momentjs) use a library rather than a regex to parse the input date
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.
Ok, I'll use date-fns
that is already present into the project to handle date parsing
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.
Fixed in 34282a4
// If the user isn't an adult a forbidden response will be provided | ||
if ( | ||
!fromNullable(spidUser.dateOfBirth) | ||
.map(isAdult) |
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 use exists(isAdult)
see https://github.com/gcanti/fp-ts/blob/1.12.0/src/Option.ts#L303
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.
Fixed in 34282a4
lgtm but we keep this one on-hold since we have to get some feedback from the legal office. |
No description provided.