Skip to content

[#168453950] Adult check at login if dateOfBirth is provided#575

Open
BurnedMarshal wants to merge 2 commits intomasterfrom
168453950-only-adult-login
Open

[#168453950] Adult check at login if dateOfBirth is provided#575
BurnedMarshal wants to merge 2 commits intomasterfrom
168453950-only-adult-login

Conversation

@BurnedMarshal
Copy link
Contributor

No description provided.

@digitalcitizenship
Copy link

digitalcitizenship commented Jan 17, 2020

Warnings
⚠️

Please include a description of your PR changes.

Affected stories

  • 🌟 #168453950: Al login del cittadino controllare la data di nascita

Generated by 🚫 dangerJS

@codecov-io
Copy link

codecov-io commented Jan 17, 2020

Codecov Report

Merging #575 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
src/controllers/authenticationController.ts 98.59% <100%> (+0.08%) ⬆️
src/utils/responses.ts 91.3% <100%> (+1.3%) ⬆️
src/utils/date.ts 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf84665...34282a4. Read the comment docs.

year: t.string
});

export const isAdult = (dateOfBirth: string): boolean => {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 34282a4

@BurnedMarshal BurnedMarshal requested a review from gunzip January 20, 2020 09:40
@gunzip
Copy link
Contributor

gunzip commented Jan 20, 2020

lgtm but we keep this one on-hold since we have to get some feedback from the legal office.

@gunzip gunzip added the on-hold label Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants