semantic-ds-toolkit
Version:
Performance-first semantic layer for modern data stacks - Stable Column Anchors & intelligent inference
41 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fx_cache_1 = require("../../src/operators/fx-cache");
describe('Operators: FXCache preload & warmup', () => {
const realFetch = global.fetch;
beforeEach(() => {
jest.useRealTimers();
const tmpFx = new fx_cache_1.FXCache(1000);
const codes = tmpFx.getSupportedCurrencies();
global.fetch = jest.fn(async (_url) => ({
ok: true,
status: 200,
json: async () => ({
rates: Object.fromEntries(codes.map((c) => [c, 1 + (c.charCodeAt(0) % 7) / 10]))
})
}));
});
afterEach(() => {
global.fetch = realFetch;
});
it('preloadRates populates cache and produces stats', async () => {
const fx = new fx_cache_1.FXCache(5_000, { dataSources: ['ecb'] });
await fx.preloadRates([
{ from: 'USD', to: 'EUR' },
{ from: 'USD', to: 'GBP' },
{ from: 'EUR', to: 'USD' }
]);
const stats = fx.getCacheStats();
expect(stats.size).toBeGreaterThanOrEqual(3);
expect(stats.oldestEntry).not.toBeNull();
expect(stats.newestEntry).not.toBeNull();
});
it('warmupCache populates many entries from ECB', async () => {
const fx = new fx_cache_1.FXCache(5_000, { dataSources: ['ecb'] });
await fx.warmupCache('USD');
const stats = fx.getCacheStats();
expect(stats.size).toBeGreaterThan(20);
expect(stats.newestEntry).toBeInstanceOf(Date);
});
});
//# sourceMappingURL=fx-cache-preload.test.js.map