Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/resources/browser-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class BrowserPools extends APIResource {
idOrName: string,
body: BrowserPoolAcquireParams,
options?: RequestOptions,
): APIPromise<BrowserPoolAcquireResponse> {
): APIPromise<BrowserPoolAcquireResponse | null> {
return this._client.post(path`/browser_pools/${idOrName}/acquire`, { body, ...options });
}

Expand Down
33 changes: 33 additions & 0 deletions tests/api-resources/browser-pools-acquire.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Kernel, { NotFoundError } from '@onkernel/sdk';

describe('browser pool acquire responses', () => {
test('returns the browser on a 200', async () => {
const client = new Kernel({
apiKey: 'test',
fetch: async () => Response.json({ session_id: 'session-1' }),
});

const result = await client.browserPools.acquire('pool', {});

expect(result?.session_id).toBe('session-1');
});

test('returns null on a 204 without retrying', async () => {
const fetch = jest.fn(async () => new Response(null, { status: 204 }));
const client = new Kernel({ apiKey: 'test', fetch });

const result = await client.browserPools.acquire('pool', {});

expect(result).toBeNull();
expect(fetch).toHaveBeenCalledTimes(1);
});

test('preserves the typed 404 error', async () => {
const client = new Kernel({
apiKey: 'test',
fetch: async () => Response.json({ code: 'not_found' }, { status: 404 }),
});

await expect(client.browserPools.acquire('missing', {})).rejects.toBeInstanceOf(NotFoundError);
});
});
Loading