Skip to content

Commit ed5726b

Browse files
committed
Test pool acquire response outcomes
1 parent 56d6cea commit ed5726b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Kernel, { NotFoundError } from '@onkernel/sdk';
2+
3+
describe('browser pool acquire responses', () => {
4+
test('returns the browser on a 200', async () => {
5+
const client = new Kernel({
6+
apiKey: 'test',
7+
fetch: async () => Response.json({ session_id: 'session-1' }),
8+
});
9+
10+
const result = await client.browserPools.acquire('pool', {});
11+
12+
expect(result?.session_id).toBe('session-1');
13+
});
14+
15+
test('returns null on a 204 without retrying', async () => {
16+
const fetch = jest.fn(async () => new Response(null, { status: 204 }));
17+
const client = new Kernel({ apiKey: 'test', fetch });
18+
19+
const result = await client.browserPools.acquire('pool', {});
20+
21+
expect(result).toBeNull();
22+
expect(fetch).toHaveBeenCalledTimes(1);
23+
});
24+
25+
test('preserves the typed 404 error', async () => {
26+
const client = new Kernel({
27+
apiKey: 'test',
28+
fetch: async () => Response.json({ code: 'not_found' }, { status: 404 }),
29+
});
30+
31+
await expect(client.browserPools.acquire('missing', {})).rejects.toBeInstanceOf(NotFoundError);
32+
});
33+
});

0 commit comments

Comments
 (0)