Add company overview skeleton and cache

This commit is contained in:
2026-03-13 19:05:17 -04:00
parent b1c9c0ef08
commit 0394f4e795
18 changed files with 1571 additions and 158 deletions

64
lib/server/prices.test.ts Normal file
View File

@@ -0,0 +1,64 @@
import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test';
import { __pricesInternals, getPriceHistory, getQuote } from './prices';
describe('price caching', () => {
const originalFetch = globalThis.fetch;
beforeEach(() => {
__pricesInternals.resetCaches();
});
afterEach(() => {
globalThis.fetch = originalFetch;
__pricesInternals.resetCaches();
});
it('reuses the cached quote within the ttl window', async () => {
const fetchMock = mock(async () => Response.json({
chart: {
result: [
{
meta: {
regularMarketPrice: 123.45
}
}
]
}
})) as unknown as typeof fetch;
globalThis.fetch = fetchMock;
const first = await getQuote('MSFT');
const second = await getQuote('MSFT');
expect(first).toBe(123.45);
expect(second).toBe(123.45);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
it('reuses cached price history within the ttl window', async () => {
const fetchMock = mock(async () => Response.json({
chart: {
result: [
{
timestamp: [1735689600, 1736294400],
indicators: {
quote: [
{
close: [100, 105]
}
]
}
}
]
}
})) as unknown as typeof fetch;
globalThis.fetch = fetchMock;
const first = await getPriceHistory('MSFT');
const second = await getPriceHistory('MSFT');
expect(first).toHaveLength(2);
expect(second).toEqual(first);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
});