OBPIH-7101 FIX. Handle null when comparing expiration dates#5159
Conversation
| const expirationDate = item?.inventoryItem?.expirationDate; | ||
| return expirationDate == null ? null : moment.utc(expirationDate); | ||
| }); | ||
| const uniqueDates = _.uniqWith(expirationDates, (arrVal, othVal) => arrVal?.isSame(othVal)); |
There was a problem hiding this comment.
This was returning null when expiration date is null, which is falsy, which uniqWith treats as "not the same", hence the error.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5159 +/- ##
============================================
+ Coverage 8.11% 8.15% +0.03%
- Complexity 937 945 +8
============================================
Files 637 637
Lines 43134 43134
Branches 10488 10488
============================================
+ Hits 3500 3517 +17
+ Misses 39097 39078 -19
- Partials 537 539 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| const uniqueDates = _.uniqWith(expirationDates, (arrVal, othVal) => arrVal?.isSame(othVal)); | ||
| const uniqueDates = _.uniqWith( | ||
| expirationDates, | ||
| (arrVal, othVal) => (arrVal == null ? othVal == null : arrVal.isSame(othVal)), |
There was a problem hiding this comment.
use ===. == comparator should be avoided in JS.
There was a problem hiding this comment.
from what I read, x == null was the suggestion because also returns true if x is undefined. I made it '==' instead of '===' to cover a more broad range of values. But I trust your opnion so I'm okay with '=='.
Co-authored-by: Kacper Chełstowski <[email protected]>
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7101
Description: Duplicate expiry date validation error was incorrectly triggering when two bins had the same lot and expiration date was null. https://jam.dev/c/1e1680e8-e3c6-44b9-994d-46d2b19af8e1
📷 Screenshots & Recordings (optional)
Fixed:
