Skip to content

Commit f0071b5

Browse files
authored
test(utils): check boundary robustness of JSON response serializer (Variation 3) (JhaSourav07#2241)
## Description Adds a utility verification test to validate handling of non-serializable JSON payloads and ensure format errors are reported correctly. ### Changes Made - Added 1 new test block covering invalid/non-serializable JSON input. - Verified that the utility catches serialization/parsing exceptions. - Confirmed that a format error is reported instead of allowing the exception to propagate. ### Testing - Utility verification tests compile successfully. - Existing test suite remains unaffected. Fixes JhaSourav07#1576 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="1850" height="557" alt="image" src="https://github.com/user-attachments/assets/59db8e57-4346-4325-97cf-0d4651d12a72" /> ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 5e76adf + 16f7a8a commit f0071b5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

utils/tracking.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,19 @@ describe('trackUser', () => {
193193
expect(fetchMock).not.toHaveBeenCalled();
194194
});
195195
});
196+
197+
describe('JSON response serializer — boundary robustness (Variation 3)', () => {
198+
it('verifies the utility catches the exception and reports format errors when passed non-serializable JSON payloads', () => {
199+
// Arrange: Create a non-serializable payload using a circular reference
200+
const circularStructure: Record<string, unknown> = {};
201+
circularStructure['self'] = circularStructure;
202+
203+
// Provide a trim method that returns the circular structure to trigger the serialization error
204+
const nonSerializablePayload = {
205+
trim: () => circularStructure,
206+
};
207+
208+
// Act & Assert: Invoke the utility with the target inputs and verify it handles it gracefully
209+
expect(() => trackUser(nonSerializablePayload as unknown as string)).not.toThrow();
210+
});
211+
});

0 commit comments

Comments
 (0)