UNPKG

@noves/noves-sdk

Version:
99 lines (90 loc) 3.95 kB
/** * 1.5.0 Release Test — Retry Mechanism & Exports (regression) * * Validates the retry system exports and basic functionality: * - RetryPresets, RetryConfigBuilder, RetryRecommendations * - RetryHelpers convenience namespace * - Preset names work with factory methods */ import { Translate, RetryPresets, RetryConfigBuilder, RetryRecommendations, RetryHelpers, DEFAULT_RETRY_CONFIG, mergeRetryConfig, } from '../dist/index'; import { section, pass, fail, runTest } from './helpers'; const API_KEY = process.env.NOVES_API_KEY!; export async function testCoreRetry() { section('CORE: Retry Mechanism & Exports (Regression)'); // 1. RetryPresets are exported await runTest('RetryPresets: exports', async () => { if (!RetryPresets) throw new Error('RetryPresets not exported'); const presets = ['PRODUCTION', 'DEVELOPMENT', 'REAL_TIME', 'BATCH_PROCESSING', 'CRITICAL', 'DISABLED']; for (const p of presets) { if (!(RetryPresets as any)[p]) { throw new Error(`RetryPresets.${p} is missing`); } } pass('RetryPresets', `All ${presets.length} presets available`); }); // 2. RetryConfigBuilder await runTest('RetryConfigBuilder: fluent API', async () => { if (!RetryConfigBuilder) throw new Error('RetryConfigBuilder not exported'); const config = RetryConfigBuilder.create() .enable() .maxAttempts(3) .delays(1000, 10000) .exponentialBackoff(2) .withJitter(true, 0.1) .build(); if (!config || !config.enabled) throw new Error('Builder produced invalid config'); pass('RetryConfigBuilder', `Built config: maxAttempts=${config.maxAttempts}`); }); // 3. RetryRecommendations await runTest('RetryRecommendations: recommendStrategy', async () => { if (!RetryRecommendations) throw new Error('RetryRecommendations not exported'); const strategy = RetryRecommendations.recommendStrategy({ environment: 'production', usage: 'general', errorTolerance: 'medium', performanceRequirement: 'balanced' }); if (!strategy) throw new Error('recommendStrategy returned null'); pass('RetryRecommendations', `Strategy: maxAttempts=${strategy.maxAttempts}`); }); // 4. RetryHelpers namespace await runTest('RetryHelpers: convenience functions', async () => { if (!RetryHelpers) throw new Error('RetryHelpers not exported'); const prod = RetryHelpers.forProduction(); const dev = RetryHelpers.forDevelopment(); const batch = RetryHelpers.forBatchProcessing(); const rt = RetryHelpers.forRealTime(); const disabled = RetryHelpers.disabled(); if (!prod || !dev || !batch || !rt || !disabled) { throw new Error('Some RetryHelpers functions returned null'); } pass('RetryHelpers', 'All convenience functions work'); }); // 5. DEFAULT_RETRY_CONFIG and mergeRetryConfig await runTest('DEFAULT_RETRY_CONFIG + mergeRetryConfig', async () => { if (!DEFAULT_RETRY_CONFIG) throw new Error('DEFAULT_RETRY_CONFIG not exported'); if (!mergeRetryConfig) throw new Error('mergeRetryConfig not exported'); const merged = mergeRetryConfig(DEFAULT_RETRY_CONFIG, { maxAttempts: 5 }); if (merged.maxAttempts !== 5) throw new Error('mergeRetryConfig did not apply override'); pass('mergeRetryConfig', `Works: maxAttempts=${merged.maxAttempts}`); }); // 6. Factory with all preset strings const presetNames = ['PRODUCTION', 'DEVELOPMENT', 'REAL_TIME', 'BATCH_PROCESSING', 'CRITICAL', 'DISABLED']; for (const presetName of presetNames) { await runTest(`Factory: retryConfig="${presetName}"`, async () => { const translate = Translate.evm({ apiKey: API_KEY, retryConfig: presetName as any }); // Just verify instantiation doesn't throw const chains = await translate.getChains(); if (!chains) throw new Error(`Failed with preset ${presetName}`); pass(`Factory: ${presetName}`, 'OK'); }); } }