Fix MSW endpoint mismatch: /metadata/object → /meta/object - #356
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@copilot 继续 |
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aligns MSW mock endpoints with the ObjectStack client’s actual /api/v1/meta/object/:name usage so that tests and Storybook no longer generate unhandled request errors, and adds the missing console mock handler for the singular meta-object route.
Changes:
- Updated MSW handlers in grid, form, and calendar plugin tests from
/api/v1/metadata/object/...to/api/v1/meta/object/...to match the ObjectStack client. - Adjusted Storybook’s browser MSW configuration to use
/api/v1/meta/object/:objectNamefor metadata requests. - Extended the console mock server to handle the singular
/meta/object/:objectNameendpoint in addition to existing plural/legacy variants.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/plugin-grid/src/ObjectGrid.msw.test.tsx |
Updates the grid test’s schema fetch handler to /api/v1/meta/object/contact, matching the adapter’s expected endpoint. |
packages/plugin-form/src/ObjectForm.msw.test.tsx |
Updates the form test’s generic schema handler to /api/v1/meta/object/:name, avoiding unhandled MSW requests during form schema loading. |
packages/plugin-calendar/src/ObjectCalendar.msw.test.tsx |
Points the calendar test’s metadata query to /api/v1/meta/object/events to align with the ObjectStack client. |
apps/console/src/mocks/server.ts |
Adds a new /meta/object/:objectName handler (parallel to the existing /metadata/object/:objectName handler) so the console mock server supports the singular meta-object route used by the client. |
.storybook/msw-browser.ts |
Switches the Storybook metadata handler to /api/v1/meta/object/:objectName, ensuring Storybook stories use the same meta-object path as the runtime client. |
| http.get(`${baseUrl}/meta/object/:objectName`, async ({ params }) => { | ||
| console.log('MSW: getting meta item for /meta/object', params.objectName); | ||
| try { | ||
| const response = await protocol.getMetaItem({ | ||
| type: 'object', | ||
| name: params.objectName as string | ||
| }); | ||
|
|
||
| // Unwrap item if present | ||
| const payload = (response && response.item) ? response.item : response; | ||
|
|
||
| return HttpResponse.json(payload || { error: 'Not found' }, { status: payload ? 200 : 404 }); | ||
| } catch (e) { |
There was a problem hiding this comment.
The new handler for ${baseUrl}/meta/object/:objectName duplicates almost the same logic as the existing ${baseUrl}/metadata/object/:objectName handler below (logging, getMetaItem call, payload unwrapping, and error handling). To reduce maintenance overhead and risk of future drift between these endpoints, consider extracting a shared helper (e.g., a function that takes the path or a common handler factory) and reuse it for both routes.
CI tests failing because MSW handlers intercepted
/api/v1/metadata/object/:namewhile ObjectStack client calls/api/v1/meta/object/:name, causing unhandled fetch requests.Changes
Test MSW handlers - Updated endpoint paths in:
packages/plugin-grid/src/ObjectGrid.msw.test.tsxpackages/plugin-form/src/ObjectForm.msw.test.tsxpackages/plugin-calendar/src/ObjectCalendar.msw.test.tsx.storybook/msw-browser.tsConsole mock server - Added missing
/meta/object/:namehandler toapps/console/src/mocks/server.ts(already had/meta/objects/:nameplural variant)Before:
After:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.