Skip to content

chore: add missing unit tests for isNotNull and lineage edge cases in cht-datasource#11062

Open
shivv23 wants to merge 4 commits into
medic:masterfrom
shivv23:chore/add-missing-cht-datasource-tests
Open

chore: add missing unit tests for isNotNull and lineage edge cases in cht-datasource#11062
shivv23 wants to merge 4 commits into
medic:masterfrom
shivv23:chore/add-missing-cht-datasource-tests

Conversation

@shivv23
Copy link
Copy Markdown

@shivv23 shivv23 commented May 13, 2026

Summary

Adds missing unit test coverage for the isNotNull type guard and edge cases for lineage utility functions in the @medic/cht-datasource shared library.

Details

Based on a test coverage audit of the cht-datasource library, the following gaps were identified and filled:

1. isNotNull type guard — 8 test cases

shared-libs/cht-datasource/src/libs/core.ts

Had zero direct unit tests despite being an exported type guard used across the library (filter(isNotNull) appears in multiple lineage functions). Added 8 parameterized cases:

Input Expected
null false
undefined false (type guard passes, no narrowing)
'value' true
0 true
'' true
false true
{} true
[] true

2. getLineageDocsById edge cases — 3 tests

Had only 1 happy-path test. Added:

  • Document not found → empty array returned
  • Database query error → error propagated
  • Null docs in query results → preserved in response

3. minifyLineage edge cases — 3 tests

Added tests for:

  • Deeply nested parent chain (recursive minification verified)
  • Extra field stripping (parent.name, type removed, only _id + parent._id kept)
  • Doc with no parent field

4. minifyDoc edge cases — 3 tests

Added tests for:

  • Extra fields stripped from full doc
  • Doc with no parent field
  • Original document immutability (minifyDoc must not mutate the input)

All tests follow the existing patterns: chai expectations, sinon stubs, and async/await where needed.

Testing

cd shared-libs/cht-datasource
npm test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant