Skip to content

Commit

Permalink
fix(fixed-periods): prevent infinite loops (#52)
Browse files Browse the repository at this point in the history
* feat(fixed-periods): add isValidPeriodType helper

* fix(fixed-periods): ensure year is always a valid int

* fix(fixed-periods): ensure startDayOfWeek is always a number

* fix(fixed-periods): throw error on invalid periodType getFixedPeriodType

* chore(fixed-periods): restructure test file

* fix(fixed-periods): throw error if getYearOffsetFromNow gets bad input

* fix(fixed-periods): add additional check to getFixedPeriodType

* fix(period-types): ensure startDate and endDate are valid dates

* fix(fixed-periods): improve validation on getMostRecentCompletedYear

* fix(fixed-periods): implement feedback
  • Loading branch information
HendrikThePendric authored Aug 17, 2021
1 parent dc5bc23 commit f9175b0
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 237 deletions.
36 changes: 18 additions & 18 deletions src/shared/fixed-periods/__snapshots__/fixed-periods.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fixedPeriods utils Period id parser should parse bi-weekly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse bi-weekly periods correctly 1`] = `
Object {
"displayName": "Bi-Week 9 - 2014-04-21 - 2014-05-04",
"endDate": "2014-05-04",
Expand All @@ -17,7 +17,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse bimonthly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse bimonthly periods correctly 1`] = `
Object {
"displayName": "November - December 2014",
"endDate": "2014-12-31",
Expand All @@ -34,7 +34,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse daily periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse daily periods correctly 1`] = `
Object {
"displayName": "2014-01-01",
"endDate": "2014-01-01",
Expand All @@ -51,7 +51,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse financial-year-april periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse financial-year-april periods correctly 1`] = `
Object {
"displayName": "April 2014 - March 2015",
"endDate": "2015-03-31",
Expand All @@ -67,7 +67,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse financial-year-july periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse financial-year-july periods correctly 1`] = `
Object {
"displayName": "July 2014 - June 2015",
"endDate": "2015-06-30",
Expand All @@ -83,7 +83,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse financial-year-november periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse financial-year-november periods correctly 1`] = `
Object {
"displayName": "November 2014 - October 2015",
"endDate": "2015-10-31",
Expand All @@ -99,7 +99,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse financial-year-october periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse financial-year-october periods correctly 1`] = `
Object {
"displayName": "October 2014 - September 2015",
"endDate": "2015-09-30",
Expand All @@ -115,7 +115,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse monthly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse monthly periods correctly 1`] = `
Object {
"displayName": "June 2014",
"endDate": "2014-06-30",
Expand All @@ -132,7 +132,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse quarterly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse quarterly periods correctly 1`] = `
Object {
"displayName": "January - March 2014",
"endDate": "2014-03-31",
Expand All @@ -149,7 +149,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse six-monthly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse six-monthly periods correctly 1`] = `
Object {
"displayName": "January - June 2014",
"endDate": "2014-06-30",
Expand All @@ -166,7 +166,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse six-monthly-april periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse six-monthly-april periods correctly 1`] = `
Object {
"displayName": "April - September 2014",
"endDate": "2014-09-30",
Expand All @@ -183,7 +183,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse weekly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse weekly periods correctly 1`] = `
Object {
"displayName": "Week 9 - 2014-02-24 - 2014-03-02",
"endDate": "2014-03-02",
Expand All @@ -200,7 +200,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse weekly-saturday periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse weekly-saturday periods correctly 1`] = `
Object {
"displayName": "Week 9 - 2014-03-01 - 2014-03-07",
"endDate": "2014-03-07",
Expand All @@ -217,7 +217,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse weekly-sunday periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse weekly-sunday periods correctly 1`] = `
Object {
"displayName": "Week 9 - 2014-02-23 - 2014-03-01",
"endDate": "2014-03-01",
Expand All @@ -234,7 +234,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse weekly-sunday periods correctly 2`] = `
exports[`Fixed period utilities Period id parser should parse weekly-sunday periods correctly 2`] = `
Object {
"displayName": "Week 9 - 2014-02-23 - 2014-03-01",
"endDate": "2014-03-01",
Expand All @@ -251,7 +251,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse weekly-thursday periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse weekly-thursday periods correctly 1`] = `
Object {
"displayName": "Week 9 - 2014-02-27 - 2014-03-05",
"endDate": "2014-03-05",
Expand All @@ -268,7 +268,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse weekly-wednessday periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse weekly-wednessday periods correctly 1`] = `
Object {
"displayName": "Week 9 - 2014-02-26 - 2014-03-04",
"endDate": "2014-03-04",
Expand All @@ -285,7 +285,7 @@ Object {
}
`;

exports[`fixedPeriods utils Period id parser should parse yearly periods correctly 1`] = `
exports[`Fixed period utilities Period id parser should parse yearly periods correctly 1`] = `
Object {
"displayName": "2014",
"endDate": "2014-12-31",
Expand Down
Loading

0 comments on commit f9175b0

Please sign in to comment.