Skip to content

Commit 77dd962

Browse files
authored
Merge pull request #90 from mcode/careplan-null-has-changed
Fixed hasChanged check within carePlanChangeReasonExtensionTemplate
2 parents a415c1e + c7ee1b4 commit 77dd962

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/templates/CarePlanWithReviewTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function carePlanReasonTemplate({ reasonCode, reasonDisplayText }) {
3030
}
3131

3232
function carePlanChangeReasonExtensionTemplate({ hasChanged, reasonCode, reasonDisplayText, effectiveDate }) {
33-
if (hasChanged === undefined || !effectiveDate) {
33+
if (hasChanged === null || !effectiveDate) {
3434
const errorMessage = 'Trying to render a CarePlanWithReviewTemplate, but a review was missing required fields; '
3535
+ 'ensure that hasChanged and effectiveDate are present on all reviews';
3636
throw new Error(errorMessage);

test/templates/carePlanWithReview.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ describe('JavaScript render CarePlan template', () => {
103103
mrn: 'abc-def',
104104
reviews: [{
105105
effectiveDate: '2020-01-23',
106-
haschanged: null,
106+
hasChanged: null,
107107
}],
108108
};
109109

110110
expect(() => carePlanWithReviewTemplate(INVALID_DATA)).toThrow(Error);
111-
expect(() => carePlanWithReviewTemplate(INVALID_REVIEW_DATA)).toThrow(Error);
111+
112+
// A null hasChanged value should cause a specific error to be thrown, an undefined hasChanged value should not
113+
const hasChangedError = 'Trying to render a CarePlanWithReviewTemplate, but a review was missing required fields; ensure that hasChanged and effectiveDate are present on all reviews';
114+
expect(() => carePlanWithReviewTemplate(INVALID_REVIEW_DATA)).toThrowError(hasChangedError);
115+
116+
INVALID_REVIEW_DATA.reviews[0].hasChanged = undefined;
117+
expect(() => carePlanWithReviewTemplate(INVALID_REVIEW_DATA)).not.toThrowError(hasChangedError);
112118
});
113119
});

0 commit comments

Comments
 (0)