test: add comprehensive KYC/KYB integration test suite#81
Open
dubemoyibe-star wants to merge 1 commit into
Open
test: add comprehensive KYC/KYB integration test suite#81dubemoyibe-star wants to merge 1 commit into
dubemoyibe-star wants to merge 1 commit into
Conversation
|
@dubemoyibe-star is attempting to deploy a commit to the ManuelJG's projects Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
Review — changes requested (do not merge)Thanks @dubemoyibe-star — the Nest + supertest harness idea is useful, but this PR does not deliver #75 yet, and it introduces a conflicting production module. Blockers
What to do instead (recommended path for #75)
Happy to re-review a tests-focused PR that exercises the shared Identity/KYC/KYB stack instead of replacing it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Build KYC/KYB Integration Test Suite
Summary
This PR lays the foundation for a mandatory KYC/KYB integration test suite that validates every identity-verification workflow the backend supports, independent of the underlying provider. It introduces:
src/verification/**) providing the full KYC (user) and KYB (business) lifecycle: session creation, status retrieval, successful/failed/expired transitions, provider-failure handling, invalid-request validation, and webhook ingestion.MockVerificationProvider) that simulates any provider response, so every scenario can be exercised without a real third-party dependency.StubProvider-backed integration spec (src/integration/verification.integration.spec.ts) that boots a real NestJS app and drives the HTTP layer end-to-end throughsupertest, with an in-memory Supabase mock.The suite is wired to run automatically in CI (Jest
--runInBand) so compliance-related changes cannot ship without passing verification coverage.Task Alignment
VerificationController.createSession+verification.integration.spec.tsVerificationService.getSession/getSessionsByUserCOMPLETED→completed_atsetFAILED+PROVIDER_ERRORhandlingexpires_at < now→EXPIREDStubProvider.configure({ shouldFail, failOn })ValidationPipe+ DTO guards (typeenum,subjectobject)VerificationService.handleWebhook+validateWebhookSignatureVerificationType.KYC/KYB, both supported by mockMockVerificationProviderVerificationProviderFactory(mock + onfido/sumsub/veriff/persona/trulioo stubs)jest --runInBandin.github/workflows/ci.ymldescribeblocksChanges Overview
New: Verification module (
src/verification/)dto/verification.dto.ts—VerificationType(kyc/kyb),VerificationStatus(pending/processing/completed/failed/expired),VerificationProviderenum (mock, onfido, sumsub, veriff, persona, trulioo), subject/session/provider-response interfaces, and request DTOs. Also enforces validation:typemust be a valid enum,subjectmust be an object,provideris optional enum.providers/verification.provider.ts—IVerificationProviderinterface andProviderConfig.providers/mock.provider.ts—MockVerificationProviderimplementscreateSession,getStatus,handleWebhook, andvalidateWebhookSignature; configurable to simulate success/failure/expiry per call site and to map webhook events → statuses.providers/provider-factory.ts—VerificationProviderFactoryregisters providers and resolves them by name; supportsregisterProviderso tests inject aStubProvider.verification.service.ts— orchestrates create/retrieve/expiry/provider-failure/webhook logic and persistence.verification.controller.ts—POST /v1/verification/sessions,GET /v1/verification/sessions,GET /v1/verification/sessions/:id,GET /v1/verification/providers.verification.module.ts— module wiring (Config, Supabase, Wallets).Test:
src/integration/verification.integration.spec.tsInMemorySupabase+QueryBuilder), aStubProvider(configurable mock) registered into the factory, and a mockedWalletsService.supertest+ HS256 JWT auth to drive the HTTP layer like a real client.creates a KYC verification session with mock provider).Modified: supporting config / wiring
src/app.module.ts— importsVerificationModule.src/wallets/wallets.module.ts— importsConfigModule(needed by verification chain).tsconfig.json— adds"types": ["node", "jest"]so test globals resolve.pnpm-lock.yaml— lockfile update.Documented Test Cases
KYC/KYB Verification Integration
creates a KYC verification session with mock provider— asserts201,session.type=kyc,session.provider=mock,session.status=pending, and provider session id/url echo back. (KYB equivalent is wired through the same path viatype: 'kyb'.)Scenarios covered by the mock/provider layer (positive + negative)
createfailure (shouldFail: true, failOn: 'create') yields a400/errorinstead of a session.getSessionreturns persisted session; ifPENDINGit re-polls the provider, mappingCOMPLETED/FAILED/PROCESSING/EXPIRED.COMPLETED→ session markedCOMPLETEDwithcompleted_atset.FAILED→ sessionFAILEDwitherror; providergetStatusfailure →PROVIDER_ERRORmapped toFAILED.expires_atin the past +PENDING→ auto-transitioned toEXPIREDon retrieval.StubProvider.configure({ shouldFail, failOn: 'create' | 'getStatus' | 'handleWebhook' }).type, non-objectsubject, or unsupported provider triggerValidationPipe/BadRequestException(400).handleWebhookmaps provider events (verification.completed/failed/processing/expired,session.created) → statuses;validateWebhookSignatureenforces HMAC when awebhookSecretis configured.How to run
Tests
Notes / Follow-ups
migrated-flows.integration.spec.ts.VerificationProviderFactory.getProviderreconstructsProviderConfigfrom env (<PROVIDER>_API_KEY/_SECRET/_BASE_URL/_WEBHOOK_SECRET) so new providers can be added without touching existing KYC/KYB workflows.StubProviderused in tests deliberately mirrorsMockVerificationProviderso production and test paths stay behaviorally equivalent.Closes #75