Skip to content

Add unit tests for internal/didit KYC client (CreateSession, GetSessionDecision) #42

Description

@Jagadeeshftw

📌 Description

internal/didit/client.go wraps the Didit KYC API (CreateSession POSTs to /v2/session/, GetSessionDecision GETs /v2/session/{id}/decision/, both with x-api-key auth and a 30s timeout) but has no test file. KYC drives the kyc.go handler and gates user verification.

💡 Why it matters: Verification status decisions depend on correctly parsing Didit responses; untested parsing risks misclassifying users' KYC state.

🧩 Requirements and context

  • Use httptest.Server to assert the x-api-key header, method, path, and workflow_id payload.
  • Cover a successful session creation and decision retrieval with realistic JSON.
  • Cover Didit error bodies and non-2xx responses, asserting the captured raw body for debugging.
  • Verify the 30s client timeout via a slow server and context deadline.
  • No real Didit network access.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b test/didit-client

2. Implement changes

  • Write/modify the relevant source: refactor NewClient to accept a base URL for tests if needed
  • Write comprehensive tests: internal/didit/client_test.go
  • Add documentation: GoDoc on response parsing
  • Include GoDoc comments on the status mapping
  • Validate security assumptions: API key must not be logged

3. Test and commit

  • Run tests:
go test ./internal/didit/...
  • Cover edge cases: error body, timeout, malformed JSON
  • Include test output and security notes in the PR description.

Example commit message

test(didit): cover KYC session creation and decision parsing

✅ Acceptance criteria

  • Header/method/path/payload asserted for both calls
  • Success and error responses covered
  • Timeout behavior tested
  • No real network calls

🔒 Security notes

Confirms the x-api-key is sent but never logged; ensures error bodies captured for debugging do not leak into client responses.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial CampaignGrantFox official campaign issuebackendBackend / API worktestingTests and coverage

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions