UNPKG

semantic-ds-toolkit

Version:

Performance-first semantic layer for modern data stacks - Stable Column Anchors & intelligent inference

39 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const globals_1 = require("@jest/globals"); const fx_cache_1 = require("../src/operators/fx-cache"); (0, globals_1.describe)('FXCache offline modes', () => { let cache; (0, globals_1.beforeEach)(() => { cache = new fx_cache_1.FXCache(500, { fallbackRates: { 'USD_EUR': 0.9, 'EUR_USD': 1.1 }, dataSources: [] }); }); (0, globals_1.it)('returns fallback rates when no network sources are configured', async () => { const result = await cache.getExchangeRate('USD', 'EUR'); (0, globals_1.expect)(result.rate).toBeCloseTo(0.9, 5); (0, globals_1.expect)(result.source).toBe('fallback'); (0, globals_1.expect)(result.confidence).toBeLessThan(1); }); (0, globals_1.it)('throws in strict offline mode when no cache exists', async () => { await (0, globals_1.expect)(cache.getExchangeRate('EUR', 'GBP', { mode: fx_cache_1.OfflineMode.STRICT_OFFLINE })).rejects.toThrow('No cached rate'); }); (0, globals_1.it)('serves stale cache in strict offline mode when available', async () => { // Populate cache using fallback await cache.getExchangeRate('USD', 'EUR', { mode: fx_cache_1.OfflineMode.CACHE_FIRST }); const cacheKey = cache.getCacheKey('USD', 'EUR'); const memoryCache = cache.memoryCache; const cached = memoryCache.get(cacheKey); cached.timestamp = Date.now() - 3600 * 1000; // force staleness memoryCache.set(cacheKey, cached); const result = await cache.getExchangeRate('USD', 'EUR', { mode: fx_cache_1.OfflineMode.STRICT_OFFLINE }); (0, globals_1.expect)(result.source).toBe('cache'); (0, globals_1.expect)(result.stale).toBeTruthy(); (0, globals_1.expect)(result.rate).toBeCloseTo(0.9, 5); }); }); //# sourceMappingURL=fx-cache.offline.test.js.map