test(vc): add tests for isCredential and isStatusListCredential type guards#70
test(vc): add tests for isCredential and isStatusListCredential type guards#70ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
Conversation
…guards Cover both type guard functions that previously had zero tests: isCredential: valid credentials, string issuer, optional fields, rejection of null/undefined/string/empty objects, and each required field missing individually. isStatusListCredential: valid status list credential, wrong subject type, missing encodedList, missing statusPurpose, regular credential without status list subject, and non-credential inputs.
WalkthroughTwo new Vitest test suites were added to validate credential objects. The first tests Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vc/src/revocation/is-status-list-credential.test.ts (1)
41-65: Consider adding a test for missingcredentialSubject.id.Per the schema at
packages/vc/src/schemas/valibot.ts:40-45,idis a required field inbitstringStatusListClaimSchema, but there's no test verifying rejection when it's missing. You have tests for missingencodedListandstatusPurpose, but not forid.📝 Suggested additional test case
it("returns false when credentialSubject is missing id", () => { expect( isStatusListCredential({ ...baseCredential, credentialSubject: { type: "BitstringStatusList", statusPurpose: "revocation", encodedList: "H4sIAAAAAAAA...", }, }), ).toBe(false) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vc/src/revocation/is-status-list-credential.test.ts` around lines 41 - 65, Add a test to is-status-list-credential.test.ts that verifies isStatusListCredential returns false when credentialSubject lacks the required id field: create a new it(...) case (e.g., "returns false when credentialSubject is missing id") passing {...baseCredential, credentialSubject: { type: "BitstringStatusList", statusPurpose: "revocation", encodedList: "H4sIAAAAAAAA..." }} into isStatusListCredential and assert .toBe(false); this mirrors the existing tests for missing encodedList and statusPurpose and ensures the bitstringStatusListClaimSchema requirement is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/vc/src/revocation/is-status-list-credential.test.ts`:
- Around line 41-65: Add a test to is-status-list-credential.test.ts that
verifies isStatusListCredential returns false when credentialSubject lacks the
required id field: create a new it(...) case (e.g., "returns false when
credentialSubject is missing id") passing {...baseCredential, credentialSubject:
{ type: "BitstringStatusList", statusPurpose: "revocation", encodedList:
"H4sIAAAAAAAA..." }} into isStatusListCredential and assert .toBe(false); this
mirrors the existing tests for missing encodedList and statusPurpose and ensures
the bitstringStatusListClaimSchema requirement is covered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aa8c6363-e383-43a1-8402-ada52601c9be
📒 Files selected for processing (2)
packages/vc/src/is-credential.test.tspackages/vc/src/revocation/is-status-list-credential.test.ts
Summary
isCredential(12 tests) andisStatusListCredential(6 tests), both previously untestedTest plan
pnpm --filter ./packages/vc test— 65 tests pass (18 new)pnpm run check— cleanSummary by CodeRabbit