-
Notifications
You must be signed in to change notification settings - Fork 351
fix(spector): handle matchers in query param validation #10259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a5ed84e
7528d51
22b55dc
006ef06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: fix | ||
| packages: | ||
| - "@typespec/spector" | ||
| --- | ||
|
|
||
| Fix query parameter matcher handling: use `resolveMatchers: false` so matcher objects (e.g. `match.dateTime`) are checked semantically instead of being serialized to plain strings before comparison. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { | ||
| expandDyns, | ||
| isMatcher, | ||
| MockApiDefinition, | ||
| MockBody, | ||
| MockMultipartBody, | ||
|
|
@@ -145,10 +146,10 @@ function createHandler(apiDefinition: MockApiDefinition, config: ResolverConfig) | |
|
|
||
| // Validate headers if present in the request | ||
| if (apiDefinition.request?.headers) { | ||
| const headers = expandDyns(apiDefinition.request.headers, config); | ||
| const headers = expandDyns(apiDefinition.request.headers, config, { resolveMatchers: false }); | ||
| Object.entries(headers).forEach(([key, value]) => { | ||
| if (key.toLowerCase() !== "content-type") { | ||
| if (Array.isArray(value)) { | ||
| if (isMatcher(value) || Array.isArray(value)) { | ||
| req.expect.deepEqual(req.headers[key], value); | ||
| } else { | ||
| req.expect.containsHeader(key.toLowerCase(), String(value)); | ||
|
|
@@ -158,9 +159,9 @@ function createHandler(apiDefinition: MockApiDefinition, config: ResolverConfig) | |
| } | ||
|
|
||
| if (apiDefinition.request?.query) { | ||
| const query = expandDyns(apiDefinition.request.query, config); | ||
| const query = expandDyns(apiDefinition.request.query, config, { resolveMatchers: false }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agent says the |
||
| Object.entries(query).forEach(([key, value]) => { | ||
| if (Array.isArray(value)) { | ||
| if (isMatcher(value) || Array.isArray(value)) { | ||
| req.expect.deepEqual(req.query[key], value); | ||
| } else { | ||
| req.expect.containsQueryParam(key, String(value)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked copilot to add test, but these may not be very meaningful. I can revert them if unhelpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that make sense, wondering if we ever need the resolveMatchers: true on. i'll investigate in a folllow up pr