Backend NestJS/Prisma, application mobile Expo (Tap to Pay Stripe), tableau de bord web Vite et documentation (cadrage en brouillon, décisions d'architecture). Secrets et fichiers locaux exclus par .gitignore. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import type Stripe from 'stripe';
|
|
import { computeKycStatus, extractAccountState, StoredRequirements } from './kyc-status';
|
|
|
|
const req = (over: Partial<StoredRequirements> = {}): StoredRequirements => ({
|
|
currentlyDue: [],
|
|
pastDue: [],
|
|
eventuallyDue: [],
|
|
pendingVerification: [],
|
|
errors: [],
|
|
...over,
|
|
});
|
|
|
|
describe('computeKycStatus', () => {
|
|
it('sans compte : not_started', () => {
|
|
expect(computeKycStatus(null)).toBe('not_started');
|
|
});
|
|
|
|
it('informations manquantes : action_required', () => {
|
|
expect(
|
|
computeKycStatus({ chargesEnabled: false, payoutsEnabled: false, requirements: req({ currentlyDue: ['identity.individual.date_of_birth.day'] }) }),
|
|
).toBe('action_required');
|
|
});
|
|
|
|
it('en attente de Stripe : pending_verification', () => {
|
|
expect(
|
|
computeKycStatus({ chargesEnabled: false, payoutsEnabled: false, requirements: req({ pendingVerification: ['identity.individual.verification'] }) }),
|
|
).toBe('pending_verification');
|
|
});
|
|
|
|
it('paiements et versements autorisés : active', () => {
|
|
expect(computeKycStatus({ chargesEnabled: true, payoutsEnabled: true, requirements: req() })).toBe('active');
|
|
});
|
|
|
|
it('actif mais nouvelle exigence en retard : action_required', () => {
|
|
expect(computeKycStatus({ chargesEnabled: true, payoutsEnabled: true, requirements: req({ pastDue: ['external_account'] }) })).toBe(
|
|
'action_required',
|
|
);
|
|
});
|
|
|
|
it('refusé : rejected', () => {
|
|
expect(computeKycStatus({ chargesEnabled: false, payoutsEnabled: false, rejected: true, requirements: req() })).toBe('rejected');
|
|
});
|
|
});
|
|
|
|
describe('extractAccountState', () => {
|
|
it('classe les exigences et lit les capacités (forme réelle renvoyée par Stripe en test)', () => {
|
|
const account = {
|
|
configuration: {
|
|
merchant: {
|
|
capabilities: {
|
|
card_payments: { status: 'restricted', status_details: [] },
|
|
stripe_balance: { payouts: { status: 'restricted', status_details: [] } },
|
|
},
|
|
},
|
|
},
|
|
requirements: {
|
|
entries: [
|
|
{
|
|
awaiting_action_from: 'user',
|
|
description: 'configuration.merchant.support.phone',
|
|
errors: [],
|
|
impact: {},
|
|
minimum_deadline: { status: 'past_due' },
|
|
requested_reasons: [],
|
|
},
|
|
{
|
|
awaiting_action_from: 'stripe',
|
|
description: 'identity.individual.verification.document',
|
|
errors: [{ code: 'verification_document_expired', description: 'Document expiré' }],
|
|
impact: {},
|
|
minimum_deadline: { status: 'currently_due' },
|
|
requested_reasons: [],
|
|
},
|
|
],
|
|
},
|
|
} as unknown as Stripe.V2.Core.Account;
|
|
|
|
const state = extractAccountState(account);
|
|
expect(state.chargesEnabled).toBe(false);
|
|
expect(state.payoutsEnabled).toBe(false);
|
|
expect(state.requirements.pastDue).toEqual(['configuration.merchant.support.phone']);
|
|
expect(state.requirements.pendingVerification).toEqual(['identity.individual.verification.document']);
|
|
expect(state.requirements.errors).toHaveLength(1);
|
|
expect(computeKycStatus(state)).toBe('action_required');
|
|
});
|
|
});
|