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

fix(date): ensures correct range for birthdate #2535

Merged
merged 2 commits into from
Nov 13, 2023

Conversation

mumumilk
Copy link
Contributor

@mumumilk mumumilk commented Nov 8, 2023

fixes #2534

@mumumilk mumumilk requested a review from a team as a code owner November 8, 2023 15:47
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #2535 (e700a61) into next (ef965da) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2535      +/-   ##
==========================================
- Coverage   99.58%   99.58%   -0.01%     
==========================================
  Files        2801     2801              
  Lines      249842   249842              
  Branches     1085     1082       -3     
==========================================
- Hits       248797   248793       -4     
- Misses       1017     1021       +4     
  Partials       28       28              
Files Coverage Δ
src/modules/date/index.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@ST-DDT ST-DDT added this to the vAnytime milestone Nov 9, 2023
src/modules/date/index.ts Outdated Show resolved Hide resolved
@ST-DDT
Copy link
Member

ST-DDT commented Nov 9, 2023

Please add these tests:

it('returns a random birthdate that is 18+ by default', () => {
// Generate the latest possible value => youngest
faker.seed(2855577693);
const refDate = new Date();
const birthdate = faker.date.birthdate({ refDate });
expect(birthdate).toBeInstanceOf(Date);
const value = birthdate.valueOf();
const refDateValue = refDate.valueOf();
expect(value).toBeLessThanOrEqual(refDateValue);
const deltaDate = new Date(refDateValue - value);
expect(deltaDate.getUTCFullYear() - 1970).toBeGreaterThanOrEqual(18);
});
it('returns a random birthdate in one year', () => {
const min = 1990;
const max = 1990;
const birthdate = faker.date.birthdate({ min, max, mode: 'year' });
// birthdate is a date object
expect(birthdate).toBeInstanceOf(Date);
expect(birthdate.toISOString()).not.toMatch(/T00:00:00.000Z/);
// Generated date is between min and max
expect(birthdate.getUTCFullYear()).toBeGreaterThanOrEqual(min);
expect(birthdate.getUTCFullYear()).toBeLessThanOrEqual(max);
});

@ST-DDT ST-DDT added c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug m: date Something is referring to the date module labels Nov 9, 2023
@mumumilk mumumilk requested a review from ST-DDT November 11, 2023 10:39
@ST-DDT ST-DDT requested review from a team November 11, 2023 10:52
@ST-DDT ST-DDT merged commit 7ce8c28 into faker-js:next Nov 13, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working m: date Something is referring to the date module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Birthdate with default values return age less than 18
4 participants