Skip to content

Commit 6073d17

Browse files
test(validations): check boundary robustness of date range formatter (Variation 1) (JhaSourav07#1689)
## Description Added focused unit tests to `lib/validations.test.ts` evaluating the parsing constraints of the `streakParamsSchema` to fulfill the **Variation 1** boundary robustness requirements. ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs, tests) ## Implementation Details - **Partial/Missing Year Parameters:** Added a test case passing a payload missing an explicit calendar year sequence (`from: '05-12'`, `to: '05-30'`) to verify that the validation layer parses it safely via implicit runtime date fallbacks without crashing. - **Omitted Date Bounds:** Added a validation check confirming that completely omitted optional date bounds evaluate gracefully to `undefined`, allowing downstream logic blocks to fall back to default ranges smoothly. - **Validation:** Verified locally that all 81 tests pass successfully inside `lib/validations.test.ts` with zero TypeScript compilation warnings or linting errors. Fixes JhaSourav07#1554 ## Checklist - [x] My code follows the code style of this project. - [x] I have performed a self-review of my own code. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] My changes generate no new warnings. - [x] I have added tests that prove my fix is effective or that my feature works. - [x] New and existing unit tests pass locally with my changes.
1 parent 7af1b4f commit 6073d17

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

lib/validations.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,45 @@ describe('streakParamsSchema — view fallback behavior', () => {
646646
expect(parse({}).view).toBe('default');
647647
});
648648
});
649+
650+
/* ==========================================================================
651+
* DATE RANGE BOUNDARY ROBUSTNESS (VARIATION 1)
652+
* ========================================================================== */
653+
654+
describe('streakParamsSchema — Date Range Boundary Robustness (Variation 1)', () => {
655+
it('should process validation safely and fallback when partial or missing year parameters are passed', () => {
656+
// Arrange: Provide a mock payload missing a full YYYY format sequence
657+
const partialYearPayload = {
658+
user: 'octocat',
659+
from: '05-12',
660+
to: '05-30',
661+
};
662+
663+
// Act: Pass the object through the validator schema matrix
664+
const result = streakParamsSchema.safeParse(partialYearPayload);
665+
666+
// Assert: The validator handles it safely using implicit date engine fallbacks
667+
expect(result.success).toBe(true);
668+
if (result.success) {
669+
expect(result.data.from).toBeDefined();
670+
expect(result.data.to).toBeDefined();
671+
}
672+
});
673+
674+
it('should pass cleanly and fallback to default ranges when date bounds are completely omitted', () => {
675+
// Arrange: Pass only the bare minimum required parameters
676+
const minimalPayload = {
677+
user: 'octocat',
678+
};
679+
680+
// Act
681+
const result = streakParamsSchema.safeParse(minimalPayload);
682+
683+
// Assert: Verify that omitted range options return undefined to use downstream defaults smoothly
684+
expect(result.success).toBe(true);
685+
if (result.success) {
686+
expect(result.data.from).toBeUndefined();
687+
expect(result.data.to).toBeUndefined();
688+
}
689+
});
690+
});

0 commit comments

Comments
 (0)