Skip to content

Commit 518c13f

Browse files
Copilothotlong
andcommitted
fix: update sveltekit adapter tests to use dispatch() catch-all pattern
The sveltekit adapter implementation uses dispatcher.dispatch() for the catch-all route (meta, data, etc.), but the test mocks were using the old handleMetadata/handleData methods that no longer exist in the code path. Updated the mock to include dispatch and aligned test assertions with the unified catch-all pattern used by all other adapters (hono, etc.). Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/d30145f6-3528-4e58-baf1-5011e72f43c4
1 parent 03ff2ed commit 518c13f

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

packages/adapters/sveltekit/src/sveltekit.test.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ const mockDispatcher = {
77
getDiscoveryInfo: vi.fn().mockReturnValue({ version: '1.0', endpoints: [] }),
88
handleAuth: vi.fn().mockResolvedValue({ handled: true, response: { body: { ok: true }, status: 200 } }),
99
handleGraphQL: vi.fn().mockResolvedValue({ data: {} }),
10-
handleMetadata: vi.fn().mockResolvedValue({ handled: true, response: { body: { objects: [] }, status: 200 } }),
11-
handleData: vi.fn().mockResolvedValue({ handled: true, response: { body: { records: [] }, status: 200 } }),
1210
handleStorage: vi.fn().mockResolvedValue({ handled: true, response: { body: {}, status: 200 } }),
11+
dispatch: vi.fn().mockResolvedValue({ handled: true, response: { body: { success: true }, status: 200 } }),
1312
};
1413

1514
vi.mock('@objectstack/runtime', () => {
@@ -167,27 +166,29 @@ describe('createRequestHandler', () => {
167166
});
168167

169168
describe('Metadata', () => {
170-
it('GET /api/meta/objects calls handleMetadata', async () => {
169+
it('GET /api/meta/objects delegates to dispatch()', async () => {
171170
const event = makeEvent('http://localhost/api/meta/objects');
172171
const res = await handler(event);
173172
expect(res.status).toBe(200);
174-
expect(mockDispatcher.handleMetadata).toHaveBeenCalledWith(
175-
'/objects',
173+
expect(mockDispatcher.dispatch).toHaveBeenCalledWith(
174+
'GET',
175+
'/meta/objects',
176+
undefined,
177+
expect.any(Object),
176178
expect.objectContaining({ request: expect.anything() }),
177-
'GET', undefined,
178179
);
179180
});
180181
});
181182

182183
describe('Data', () => {
183-
it('GET /api/data/account calls handleData', async () => {
184+
it('GET /api/data/account delegates to dispatch()', async () => {
184185
const event = makeEvent('http://localhost/api/data/account');
185186
const res = await handler(event);
186187
expect(res.status).toBe(200);
187-
const json = await res.json();
188-
expect(json.records).toBeDefined();
189-
expect(mockDispatcher.handleData).toHaveBeenCalledWith(
190-
'/account', 'GET', {},
188+
expect(mockDispatcher.dispatch).toHaveBeenCalledWith(
189+
'GET',
190+
'/data/account',
191+
undefined,
191192
expect.any(Object),
192193
expect.objectContaining({ request: expect.anything() }),
193194
);
@@ -198,15 +199,17 @@ describe('createRequestHandler', () => {
198199
const event = makeEvent('http://localhost/api/data/account', 'POST', body);
199200
const res = await handler(event);
200201
expect(res.status).toBe(200);
201-
expect(mockDispatcher.handleData).toHaveBeenCalledWith(
202-
'/account', 'POST', body,
202+
expect(mockDispatcher.dispatch).toHaveBeenCalledWith(
203+
'POST',
204+
'/data/account',
205+
body,
203206
expect.any(Object),
204207
expect.objectContaining({ request: expect.anything() }),
205208
);
206209
});
207210

208211
it('returns 404 when not handled', async () => {
209-
mockDispatcher.handleData.mockResolvedValueOnce({ handled: false });
212+
mockDispatcher.dispatch.mockResolvedValueOnce({ handled: false });
210213
const event = makeEvent('http://localhost/api/data/missing');
211214
const res = await handler(event);
212215
expect(res.status).toBe(404);
@@ -227,13 +230,14 @@ describe('createRequestHandler', () => {
227230

228231
describe('Error handling', () => {
229232
it('returns 404 for unknown routes', async () => {
233+
mockDispatcher.dispatch.mockResolvedValueOnce({ handled: false });
230234
const event = makeEvent('http://localhost/api/unknown');
231235
const res = await handler(event);
232236
expect(res.status).toBe(404);
233237
});
234238

235239
it('returns 500 on generic error', async () => {
236-
mockDispatcher.handleData.mockRejectedValueOnce(new Error());
240+
mockDispatcher.dispatch.mockRejectedValueOnce(new Error());
237241
const event = makeEvent('http://localhost/api/data/account');
238242
const res = await handler(event);
239243
expect(res.status).toBe(500);
@@ -242,7 +246,7 @@ describe('createRequestHandler', () => {
242246

243247
describe('toResponse', () => {
244248
it('handles redirect result', async () => {
245-
mockDispatcher.handleData.mockResolvedValueOnce({
249+
mockDispatcher.dispatch.mockResolvedValueOnce({
246250
handled: true,
247251
result: { type: 'redirect', url: 'https://example.com' },
248252
});
@@ -253,7 +257,7 @@ describe('createRequestHandler', () => {
253257
});
254258

255259
it('handles generic result objects', async () => {
256-
mockDispatcher.handleData.mockResolvedValueOnce({
260+
mockDispatcher.dispatch.mockResolvedValueOnce({
257261
handled: true,
258262
result: { foo: 'bar' },
259263
});

0 commit comments

Comments
 (0)