Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
remains lazy (cold-start only) via `ensureApp()` / `ensureKernel()` in `_kernel.ts`.

### Fixed
- **SvelteKit adapter test failures** — Updated test mock to include `dispatch()` method and
aligned Metadata, Data, Error handling, and toResponse test assertions with the unified
catch-all dispatch pattern used by the implementation and all other adapters (e.g. Hono).
Removed obsolete `handleMetadata`/`handleData` references from the mock.
- **Vercel serverless 404 fix** — The previous `api/[...path].ts` path-normalisation fix is now
superseded by the Hono adapter migration above. The new `api/index.ts` entrypoint combined with
Vercel rewrites (`/api/*` → `/api`) eliminates the routing ambiguity that caused 404s.
Expand Down
38 changes: 21 additions & 17 deletions packages/adapters/sveltekit/src/sveltekit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ const mockDispatcher = {
getDiscoveryInfo: vi.fn().mockReturnValue({ version: '1.0', endpoints: [] }),
handleAuth: vi.fn().mockResolvedValue({ handled: true, response: { body: { ok: true }, status: 200 } }),
handleGraphQL: vi.fn().mockResolvedValue({ data: {} }),
handleMetadata: vi.fn().mockResolvedValue({ handled: true, response: { body: { objects: [] }, status: 200 } }),
handleData: vi.fn().mockResolvedValue({ handled: true, response: { body: { records: [] }, status: 200 } }),
handleStorage: vi.fn().mockResolvedValue({ handled: true, response: { body: {}, status: 200 } }),
dispatch: vi.fn().mockResolvedValue({ handled: true, response: { body: { success: true }, status: 200 } }),
};

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

describe('Metadata', () => {
it('GET /api/meta/objects calls handleMetadata', async () => {
it('GET /api/meta/objects delegates to dispatch()', async () => {
const event = makeEvent('http://localhost/api/meta/objects');
const res = await handler(event);
expect(res.status).toBe(200);
expect(mockDispatcher.handleMetadata).toHaveBeenCalledWith(
'/objects',
expect(mockDispatcher.dispatch).toHaveBeenCalledWith(
'GET',
'/meta/objects',
undefined,
expect.any(Object),
expect.objectContaining({ request: expect.anything() }),
'GET', undefined,
);
});
});

describe('Data', () => {
it('GET /api/data/account calls handleData', async () => {
it('GET /api/data/account delegates to dispatch()', async () => {
const event = makeEvent('http://localhost/api/data/account');
const res = await handler(event);
expect(res.status).toBe(200);
const json = await res.json();
expect(json.records).toBeDefined();
expect(mockDispatcher.handleData).toHaveBeenCalledWith(
'/account', 'GET', {},
expect(mockDispatcher.dispatch).toHaveBeenCalledWith(
'GET',
'/data/account',
undefined,
expect.any(Object),
expect.objectContaining({ request: expect.anything() }),
);
Expand All @@ -198,15 +199,17 @@ describe('createRequestHandler', () => {
const event = makeEvent('http://localhost/api/data/account', 'POST', body);
const res = await handler(event);
expect(res.status).toBe(200);
expect(mockDispatcher.handleData).toHaveBeenCalledWith(
'/account', 'POST', body,
expect(mockDispatcher.dispatch).toHaveBeenCalledWith(
'POST',
'/data/account',
body,
expect.any(Object),
expect.objectContaining({ request: expect.anything() }),
);
});

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

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

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

describe('toResponse', () => {
it('handles redirect result', async () => {
mockDispatcher.handleData.mockResolvedValueOnce({
mockDispatcher.dispatch.mockResolvedValueOnce({
handled: true,
result: { type: 'redirect', url: 'https://example.com' },
});
Expand All @@ -253,7 +257,7 @@ describe('createRequestHandler', () => {
});

it('handles generic result objects', async () => {
mockDispatcher.handleData.mockResolvedValueOnce({
mockDispatcher.dispatch.mockResolvedValueOnce({
handled: true,
result: { foo: 'bar' },
});
Expand Down
Loading