test(query): add regression coverage for vue-query header params (#1026) - #3379
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an OpenAPI spec and Orval config to generate Vue Query + axios code with header parameters, includes generated model and endpoints snapshots, and a Vitest that checks query key getters do not reference headers while the HTTP function still accepts and unrefs headers. ChangesVue Query Header Parameters Test Case
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a regression test fixture and snapshot coverage for issue #1026, verifying that the Vue Query key getter does not incorrectly reference headers when headers: true is configured.
Changes:
- New OpenAPI spec with header parameters to reproduce issue #1026.
- New
issue1026entry in the Vue Query test config plus generated snapshots. - New focused regression test asserting the query key getter does not reference
headers.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/specifications/issue-1026.yaml | New OpenAPI fixture with header parameters. |
| tests/configs/vue-query.config.ts | Adds issue1026 Vue Query generation config. |
| tests/api-generation.spec.ts | Adds regression test for the query key getter. |
| tests/snapshots/vue-query/issue-1026/endpoints.ts | Snapshot of generated endpoints. |
| tests/snapshots/vue-query/issue-1026/model/someEndpointResult.ts | Snapshot of generated result model. |
| tests/snapshots/vue-query/issue-1026/model/index.ts | Snapshot of generated model barrel file. |
| tests/snapshots/vue-query/issue-1026/model/getSomeEndpointHeaders.ts | Snapshot of generated headers type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // The getter must not reference `headers` at all - it is neither a parameter | ||
| // nor a query-key segment here. | ||
| expect(queryKeyFn).not.toContain('headers'); |
| // Slice out the `getGetSomeEndpointQueryKey` declaration body. | ||
| const marker = 'export const getGetSomeEndpointQueryKey = ('; | ||
| const start = content.indexOf(marker); | ||
| expect(start, `${marker} should be generated`).toBeGreaterThan(-1); | ||
| const end = content.indexOf('as const', start); | ||
| expect(end, `${marker} body should be terminated`).toBeGreaterThan(start); | ||
| const queryKeyFn = content.slice(start, end); |
There was a problem hiding this comment.
Thanks — I'm keeping the indexOf('as const') slicing here for consistency with the sibling react-query issue-708 test in this same file (lines 96-103), which already establishes exactly this pattern for the same kind of query-key-getter assertion. Switching only this test to a different slicing strategy would make the two diverge.
Also, this doesn't slice silently on missing as const: indexOf returns -1, and the expect(end, ...).toBeGreaterThan(start) guard right below fails with a clear "body should be terminated" message before the slice is used. If the slicing approach should change, it'd be better done for both tests together, which is out of scope for this regression-test PR.
Overview
Adds regression test coverage for #1026, where the generated Vue Query key getter referenced an undeclared
headersvariable (headers = unref(headers);) and threwReferenceError: headers is not definedat runtime whenheaders: truewas enabled.The underlying bug is already fixed (the Vue query key getter no longer unref's params, see the
Note: do not unref() params in Vuecomment inpackages/query/src/query-generator.ts). However, no test exercised thevue-query+headers: truecombination, so the scenario could silently regress. This PR closes that gap without any source changes.Changes
tests/specifications/issue-1026.yaml— new minimal OpenAPI spec with a header-only GET endpoint (Language-Id,Country-Id,TimeZone), mirroring the issue report.tests/configs/vue-query.config.ts— newissue1026config entry (client: vue-query,httpClient: axios,mode: split,headers: true), matching the configuration from the issue.tests/__snapshots__/vue-query/issue-1026/— generated snapshot fixtures.tests/api-generation.spec.ts— new focused testvue-query issue-1026 keeps header params out of the query key getter, which slices out thegetGetSomeEndpointQueryKeygetter and asserts it never referencesheaders, while confirming the HTTP function still receives and unref'sheaders.The scenario is now guarded at three layers: the snapshot test, the focused assertion, and
scripts/typecheck-generated.mjs(an undeclaredheadersfails to compile). Reintroducing the bug into the generated fixture was verified to fail all three.Related
headers: truein config #1026Summary by CodeRabbit