[#168453950] Adult check at login if dateOfBirth is provided#575
[#168453950] Adult check at login if dateOfBirth is provided#575BurnedMarshal wants to merge 2 commits intomasterfrom
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.
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.
Ok, I'll use date-fns that is already present into the project to handle date parsing
| // 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.
you can use exists(isAdult) see https://github.com/gcanti/fp-ts/blob/1.12.0/src/Option.ts#L303
|
lgtm but we keep this one on-hold since we have to get some feedback from the legal office. |
No description provided.