-
Notifications
You must be signed in to change notification settings - Fork 14
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
#1929 - Current days of study/studybreaks count is 1 short of total #1975
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
20ddc7d
initial commit
andrepestana-aot 0ca1a6e
added form and more tests
andrepestana-aot 027a28d
changed to make dateDifference function to be always inclusive
andrepestana-aot 7e6bd7c
removed duplicate test
andrepestana-aot a2374a7
changed toEqual() to toStrictEqual()
andrepestana-aot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
247 changes: 247 additions & 0 deletions
247
.../_tests_/unit/education-program-offering.service-getCalculatedStudyBreaksAndWeeks.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
import { OfferingStudyBreakCalculationContext } from "../../education-program-offering-validation.models"; | ||
import { EducationProgramOfferingService } from "../../education-program-offering.service"; | ||
|
||
describe("EducationProgramOfferingService-getCalculatedStudyBreaksAndWeeks", () => { | ||
it("Should calculate funded study period and total days when study start and end study dates are available.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "2023-01-01", | ||
studyEndDate: "2023-01-10", | ||
studyBreaks: [], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: 1, | ||
fundedStudyPeriodDays: 10, | ||
studyBreaks: [], | ||
sumOfTotalEligibleBreakDays: 0, | ||
sumOfTotalIneligibleBreakDays: 0, | ||
totalDays: 10, | ||
totalFundedWeeks: 2, | ||
unfundedStudyPeriodDays: 0, | ||
}); | ||
}); | ||
|
||
it("Should not calculate funded study period days and total days when study start date is not available.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "", | ||
studyEndDate: "2023-01-10", | ||
studyBreaks: [], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: NaN, | ||
fundedStudyPeriodDays: NaN, | ||
studyBreaks: [], | ||
sumOfTotalEligibleBreakDays: 0, | ||
sumOfTotalIneligibleBreakDays: 0, | ||
totalDays: NaN, | ||
totalFundedWeeks: NaN, | ||
unfundedStudyPeriodDays: NaN, | ||
}); | ||
}); | ||
|
||
it("Should not calculate funded study period days and total days when study end date is not available.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "2023-01-01", | ||
studyEndDate: "", | ||
studyBreaks: [], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: NaN, | ||
fundedStudyPeriodDays: NaN, | ||
studyBreaks: [], | ||
sumOfTotalEligibleBreakDays: 0, | ||
sumOfTotalIneligibleBreakDays: 0, | ||
totalDays: NaN, | ||
totalFundedWeeks: NaN, | ||
unfundedStudyPeriodDays: NaN, | ||
}); | ||
}); | ||
|
||
it("Should calculate study breaks when start and end study break dates available.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "", | ||
studyEndDate: "", | ||
studyBreaks: [ | ||
{ | ||
breakStartDate: "2023-05-29", | ||
breakEndDate: "2023-06-06", | ||
}, | ||
{ | ||
breakStartDate: "2023-06-08", | ||
breakEndDate: "2023-06-13", | ||
}, | ||
], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: NaN, | ||
fundedStudyPeriodDays: NaN, | ||
studyBreaks: [ | ||
{ | ||
breakDays: 9, | ||
breakEndDate: "2023-06-06", | ||
breakStartDate: "2023-05-29", | ||
eligibleBreakDays: 9, | ||
ineligibleBreakDays: 0, | ||
}, | ||
{ | ||
breakDays: 6, | ||
breakEndDate: "2023-06-13", | ||
breakStartDate: "2023-06-08", | ||
eligibleBreakDays: 6, | ||
ineligibleBreakDays: 0, | ||
}, | ||
], | ||
sumOfTotalEligibleBreakDays: 15, | ||
sumOfTotalIneligibleBreakDays: 0, | ||
totalDays: NaN, | ||
totalFundedWeeks: NaN, | ||
unfundedStudyPeriodDays: NaN, | ||
}); | ||
}); | ||
|
||
it("Should not calculate study breaks when start study break date is not available.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "", | ||
studyEndDate: "", | ||
studyBreaks: [ | ||
{ | ||
breakStartDate: "", | ||
breakEndDate: "2023-06-06", | ||
}, | ||
], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: NaN, | ||
fundedStudyPeriodDays: NaN, | ||
studyBreaks: [], | ||
sumOfTotalEligibleBreakDays: 0, | ||
sumOfTotalIneligibleBreakDays: 0, | ||
totalDays: NaN, | ||
totalFundedWeeks: NaN, | ||
unfundedStudyPeriodDays: NaN, | ||
}); | ||
}); | ||
|
||
it("Should not calculate study breaks when end study break date is not available.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "", | ||
studyEndDate: "", | ||
studyBreaks: [ | ||
{ | ||
breakStartDate: "2023-06-06", | ||
breakEndDate: "", | ||
}, | ||
], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: NaN, | ||
fundedStudyPeriodDays: NaN, | ||
studyBreaks: [], | ||
sumOfTotalEligibleBreakDays: 0, | ||
sumOfTotalIneligibleBreakDays: 0, | ||
totalDays: NaN, | ||
totalFundedWeeks: NaN, | ||
unfundedStudyPeriodDays: NaN, | ||
}); | ||
}); | ||
|
||
it("Should calculate eligible break days as a maximum of 21 days when a study break exceeds it.", () => { | ||
//Arrange | ||
const offeringStudyBreakCalculationContext: OfferingStudyBreakCalculationContext = | ||
{ | ||
studyStartDate: "2023-05-29", | ||
studyEndDate: "2023-09-29", | ||
studyBreaks: [ | ||
{ | ||
breakStartDate: "2023-06-08", | ||
breakEndDate: "2023-06-30", | ||
}, | ||
], | ||
}; | ||
|
||
// Act | ||
const calculatedStudyBreaksAndWeeks = | ||
EducationProgramOfferingService.getCalculatedStudyBreaksAndWeeks( | ||
offeringStudyBreakCalculationContext, | ||
); | ||
|
||
// Assert | ||
expect(calculatedStudyBreaksAndWeeks).toStrictEqual({ | ||
allowableStudyBreaksDaysAmount: 12.4, | ||
fundedStudyPeriodDays: 113.4, | ||
studyBreaks: [ | ||
{ | ||
breakDays: 23, | ||
breakEndDate: "2023-06-30", | ||
breakStartDate: "2023-06-08", | ||
eligibleBreakDays: 21, | ||
ineligibleBreakDays: 2, | ||
}, | ||
], | ||
sumOfTotalEligibleBreakDays: 21, | ||
sumOfTotalIneligibleBreakDays: 2, | ||
totalDays: 124, | ||
totalFundedWeeks: 17, | ||
unfundedStudyPeriodDays: 10.6, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Great to see some tests added to this ❤️