Skip to content

Commit 0fc9a57

Browse files
committed
chore: test cov
1 parent fd040a8 commit 0fc9a57

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

packages/ramps-controller/src/RampsController.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ describe('RampsController', () => {
249249
});
250250
});
251251

252+
it('stores error state when request fails with non-Error value', async () => {
253+
await withController(async ({ controller }) => {
254+
const fetcher = async (): Promise<string> => {
255+
throw 'String error';
256+
};
257+
258+
await expect(
259+
controller.executeRequest('error-key-string', fetcher),
260+
).rejects.toBe('String error');
261+
262+
const requestState = controller.state.requests['error-key-string'];
263+
expect(requestState?.status).toBe(RequestStatus.ERROR);
264+
expect(requestState?.error).toBe('String error');
265+
});
266+
});
267+
252268
it('sets loading state while request is in progress', async () => {
253269
await withController(async ({ controller }) => {
254270
let resolvePromise: (value: string) => void;
@@ -399,6 +415,47 @@ describe('RampsController', () => {
399415
},
400416
);
401417
});
418+
419+
it('handles entries with missing timestamps during eviction', async () => {
420+
await withController(
421+
{ options: { requestCacheMaxSize: 2 } },
422+
async ({ controller }) => {
423+
// Manually inject cache entries with missing timestamps
424+
// This shouldn't happen in normal usage but tests the defensive fallback
425+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
426+
(controller as any).update((state: any) => {
427+
state.requests['no-timestamp-1'] = {
428+
status: RequestStatus.SUCCESS,
429+
data: 'old-data-1',
430+
error: null,
431+
};
432+
state.requests['no-timestamp-2'] = {
433+
status: RequestStatus.SUCCESS,
434+
data: 'old-data-2',
435+
error: null,
436+
};
437+
state.requests['with-timestamp'] = {
438+
status: RequestStatus.SUCCESS,
439+
data: 'newer-data',
440+
error: null,
441+
timestamp: Date.now(),
442+
lastFetchedAt: Date.now(),
443+
};
444+
});
445+
446+
// Adding a fourth entry should trigger eviction of 2 entries
447+
await controller.executeRequest('key4', async () => 'data4');
448+
449+
const keys = Object.keys(controller.state.requests);
450+
expect(keys).toHaveLength(2);
451+
// Entries without timestamps should be evicted first (treated as timestamp 0)
452+
expect(keys).not.toContain('no-timestamp-1');
453+
expect(keys).not.toContain('no-timestamp-2');
454+
expect(keys).toContain('with-timestamp');
455+
expect(keys).toContain('key4');
456+
},
457+
);
458+
});
402459
});
403460

404461
describe('getRequestState', () => {

0 commit comments

Comments
 (0)