test(shared,frontend): Add unit test coverage for schemas, API client, and storeAction#125
test(shared,frontend): Add unit test coverage for schemas, API client, and storeAction#125
Conversation
…lient, and storeAction Add 64 unit tests across shared package and frontend, covering validation schemas (auth, circles, encounters, friends), phone number normalization, the API client (auth headers, error handling, content types), and the generic store action wrapper. Sets up vitest in the shared package. Closes #117 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
||
| await expect(apiRequest('/api/test')).rejects.toThrow(ApiError); | ||
|
|
||
| try { |
There was a problem hiding this comment.
catch can pass silently
If the second apiRequest() call doesn't throw (e.g. due to a future mock refactor), the catch block is skipped and all three expect() calls inside it are silently omitted — the test still passes. The same pattern appears at the equivalent block below (line ~181).
Suggested fix — use .rejects.toMatchObject() to assert both the throw and its properties in one guaranteed step:
await expect(apiRequest('/api/test')).rejects.toMatchObject({
statusCode: 422,
message: 'Validation failed',
code: 'VALIDATION_ERROR',
});Apply the same refactor to the second error test (lines ~172-188).
| Commit 01f4f30 | Reviewed 2026-03-08 | Status: Approved. Critical: 0, Important: 0, Suggestion: 1. Solid test additions closing 117. 64 new tests across shared and frontend. The previously flagged bare-catch issue was fixed. One suggestion: DateInputSchema in friends.test.ts only covers valid inputs - no negative test cases for invalid date formats or date_type values, unlike every other schema in the same file. |
…ceOf(type.errors) Produces more informative test failure messages by showing the actual arktype validation error summary instead of a generic instanceof check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
No new issues found in the refactor commit (d5a7164). The toHaveProperty(summary) change is a clean improvement. The pre-existing catch-block issue from the previous review remains open.
…sertions Captures exact arktype error messages so any change in validation wording surfaces as a clear diff rather than a silent pass. Also excludes test files from tsc --build to avoid union type errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…hObject The bare catch blocks could pass silently if the call didn't throw. Using rejects.toMatchObject guarantees both the throw and its properties are asserted in one step. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| date_type: 'anniversary', | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
💡 Testing: DateInputSchema only covers valid inputs
Unlike the other schemas in this file, DateInputSchema has no negative test cases. Consider adding tests for invalid inputs to maintain consistent coverage:
it('rejects an invalid date format', () => {
const result = DateInputSchema({
date_value: '15-05-1990', // DD-MM-YYYY instead of YYYY-MM-DD
date_type: 'birthday',
});
expect(result.summary).toContain('invalid');
});
it('rejects an invalid date_type', () => {
const result = DateInputSchema({
date_value: '1990-05-15',
date_type: 'graduation', // not a valid type
});
expect(result.summary).toBeDefined();
});There was a problem hiding this comment.
Code review complete at commit 01f4f30. No critical or important issues found. One suggestion posted inline regarding DateInputSchema missing negative test cases.
Address PR review suggestion by adding a test for invalid date_type values, consistent with negative tests on other schemas in the file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code review complete at commit af79c73. No new issues found. Previously flagged catch-block concern in client.test.ts is resolved in the current state (all error tests use rejects.toMatchObject/rejects.toThrow). Pre-existing DateInputSchema suggestion remains open (inline comment on friends.test.ts:128).
|
🎉 This PR is included in version 2.65.8 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
packages/shared/with node environment for pure-logic schema testsPasswordSchema,CircleInputSchema,EncounterInputSchema,PhoneInputSchema,EmailInputSchema,UrlInputSchema,DateInputSchema,SocialProfileInputSchema,ProfessionalHistoryInputSchema, andnormalizePhoneNumberapiRequest(auth headers, content types, error handling, credentials) andstoreAction(loading state, success/error flows, re-throw behavior)Test plan
cd packages/shared && pnpm vitest run— 43 tests passcd apps/frontend && pnpm vitest run— 21 tests passpnpm test— full monorepo suite passes (including backend + PHP)Closes #117
🤖 Generated with Claude Code