/

Scenario Catalog (dz-sandbox)

Every scenario controls how mocks respond deterministically, without merchant accounts or random flakes.

Scenario Resolution Precedence

  1. X-DZ-Scenario: <name> HTTP header on a single request (highest priority)
  2. Per-resource binding (PUT /__control/scenario/{provider}/{resourceId})
  3. Sequence step (PUT /__control/scenario/{provider} with sequence: [...] — e.g. gateway_500 first, success second)
  4. Provider default (PUT /__control/scenario/{provider})
  5. Fallback (created_ok for yalidine, success otherwise)

Payment & Network Scenarios

NameBehaviorReal-World Failure Tested
successPayment completes cleanly; signed webhook sent once (Chargily)Happy path baseline
declinedIssuer declines card/payment (errorCode / failure redirect + checkout.failed)Graceful failure UI, avoid marking order paid
insufficient_fundsInsufficient balance rejectionClear customer error messaging
expired_cardExpired card rejectionCard expiry validation & retry flow
user_cancelledCustomer aborts on hosted checkout page (checkout.canceled / SATIM failUrl)Unblocking reserved stock when abandoned
timeoutHolds socket open for DZ_TIMEOUT_MS (default 30000ms) then returns 504HTTP client timeout + circuit breaker behavior
slowAdds 1500ms latency before normal responseFrontend spinners & non-blocking checkout handlers
gateway_500Returns HTTP 500 GATEWAY_ERROR immediatelyRetry logic without duplicate order creation
network_dropDestroys TCP socket mid-flight before HTTP headersECONNRESET / undelivered response recovery
duplicate_webhookPayment succeeds and delivers the identical webhook twiceIdempotency — prevents double fulfillment / double shipping
delayed_webhookSchedules webhook 30s ahead on VirtualClockHandling redirect-before-webhook race (pending UI state)
out_of_order_webhooksEmits multi-step webhooks in reverse chronological orderState machine rejecting stale transitions
webhook_bad_signatureDelivers webhook with tampered HMAC-SHA256 signature headerRejecting spoofed webhooks with HTTP 401/403
webhook_never_sentPayment succeeds on gateway, zero webhooks emittedPolling / manual confirmation (confirmOrder.do / GET /checkouts/:id) fallback
double_charge_attemptRejects second charge/confirm with HTTP 409 ALREADY_PAIDDouble-submit protection on checkout
partial_refundSATIM refund.do refunds partial amount instead of full depositReconciliation of partially refunded balances
refund_failureSATIM refund.do fails with HTTP 422 REFUND_REJECTEDAdmin refund error surfaced cleanly instead of silent failure
rate_limitedReturns HTTP 429 with Retry-After: 5 and X-RateLimit-Remaining: 0Exponential backoff honoring Retry-After
auth_failedForces HTTP 401 UNAUTHORIZEDSurfacing rotated/invalid key alerts early

Delivery Scenarios (mock-yalidine)

NameBehaviorReal-World Failure Tested
created_okCreates COD parcel cleanly (yal-XXXXXX), valid wilaya/commune/phone checks runHappy path baseline
invalid_wilayaRejects parcel creation with HTTP 422 INVALID_WILAYACatching bad wilaya codes/names before order confirmation
invalid_communeRejects parcel with HTTP 422 INVALID_COMMUNEPreventing mismatched wilaya <-> commune pairs
phone_rejectedRejects phone failing 05/06/07 10-digit format check with HTTP 422Form validation before courier submission
lifecycle_fastSchedules Préparation -> Expédié -> En livraison -> Livré at +1m, +3m, +5m on VirtualClockTesting full delivery tracking via clock/advance in milliseconds
returned_to_senderSchedules failed attempt -> Retourné au vendeur at +4m on VirtualClockRestocking inventory + COD cancellation when buyer refuses
delivery_failed_retryFirst attempt Tentative échouée, second attempt LivréHandling intermediate failure statuses before final delivery
status_stuckLeaves parcel stuck in preparation indefinitelyAlerting operations on stale shipments

Mobile Banking Scenarios (mock-baridimob)

NameBehaviorReal-World Failure Tested
invalid_otpReturns result 109 (invalid OTP) on device confirmationIncorrect SMS verification code handling
expired_otpReturns result 110 (expired OTP) on device confirmationExpired SMS verification code and resend flow
too_many_attemptsReturns result 111 (too many failed attempts)Rate-limiting & brute-force lockdown UI
account_lockedReturns result 104 (account locked) on loginAccount suspension error handling
session_expiredReturns result 143 (session expired) on protected endpointsToken refresh / re-login redirection
device_confirm_requiredForces login to return result 107 (device confirmation required)Triggering 2FA / device pairing flow
insufficient_fundsRejects transfer with result 115 (insufficient balance)Handling transfer balance check rejections

Custom Scenarios (YAML / JSON Hot-Reload)

Drop .yaml or .json files in ./scenarios (or set DZ_SCENARIOS_DIR):

scenarios:
  - name: chargily_slow_duplicate
    provider: chargily
    category: payment
    description: Slow 350ms checkout + 2 duplicate paid webhooks.
    behavior:
      outcome: success
      latencyMs: 350
      webhook:
        count: 2
        delayMs: 50

Files are validated with Zod (ScenarioDefinitionSchema) on load and reloaded automatically when edited.

box.style.display = "block"; if (!hits.length) { box.innerHTML = "
" + noResultsText + "
"; return; } box.innerHTML = hits.map(function (hit) { return "" + hit.title.replace(/" + hit.path + " — " + hit.excerpt.replace(/"; }).join(""); }); })();