Skip to content

test(vc): add tests for isCredential and isStatusListCredential type guards#70

Open
ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
ak68a:test/vc-type-guards
Open

test(vc): add tests for isCredential and isStatusListCredential type guards#70
ak68a wants to merge 2 commits intoagentcommercekit:mainfrom
ak68a:test/vc-type-guards

Conversation

@ak68a
Copy link

@ak68a ak68a commented Mar 25, 2026

Summary

  • Add tests for isCredential (12 tests) and isStatusListCredential (6 tests), both previously untested
  • Covers valid inputs, missing required fields, wrong types, and non-credential inputs

Test plan

  • pnpm --filter ./packages/vc test — 65 tests pass (18 new)
  • pnpm run check — clean

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for credential validation, including tests for standard W3C credentials with optional fields and status list credentials. Test suites validate correct acceptance of valid credentials and proper rejection of invalid inputs, missing required properties, and edge cases.

AI Disclosure: This PR was developed with assistance from Claude Code (Claude Opus).

ak68a added 2 commits March 25, 2026 16:52
…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.
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2026

Walkthrough

Two new Vitest test suites were added to validate credential objects. The first tests isCredential, verifying it correctly identifies valid W3C credentials with required fields and rejects invalid inputs. The second tests isStatusListCredential, confirming proper validation of status list credential structure. Both suites cover positive cases and edge cases.

Changes

Cohort / File(s) Summary
Credential Validator Tests
packages/vc/src/is-credential.test.ts, packages/vc/src/revocation/is-status-list-credential.test.ts
Added Vitest test suites with comprehensive positive and negative test cases for isCredential and isStatusListCredential validators, covering required fields, optional fields, and invalid input scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: adding tests for two specific type guard functions (isCredential and isStatusListCredential) in the vc package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/vc/src/revocation/is-status-list-credential.test.ts (1)

41-65: Consider adding a test for missing credentialSubject.id.

Per the schema at packages/vc/src/schemas/valibot.ts:40-45, id is a required field in bitstringStatusListClaimSchema, but there's no test verifying rejection when it's missing. You have tests for missing encodedList and statusPurpose, but not for id.

📝 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

📥 Commits

Reviewing files that changed from the base of the PR and between f0e8c6c and 03af414.

📒 Files selected for processing (2)
  • packages/vc/src/is-credential.test.ts
  • packages/vc/src/revocation/is-status-list-credential.test.ts

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