Skip to content

Commit

Permalink
[@typespec/http-specs] - Fix explode query check of mockapi for route…
Browse files Browse the repository at this point in the history
…s test case (#4680)

A fix has been made to the routes test case in the `cadl-ranch`
repository at Azure/cadl-ranch#742. This was
done to fix Azure/cadl-ranch#731.

This PR is to bring those changes to the `typespec` repository.
`test:e2e` script is working fine.

Please review and approve. Thanks
  • Loading branch information
sarangan12 authored Oct 10, 2024
1 parent 58bd612 commit 5caa913
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/http-specs/specs/routes/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,25 @@ function createTests(uri: string) {
status: 204,
},
handler: (req: MockRequest) => {
const queryMap = new Map<string, string | string[]>();
for (const [key, value] of url.searchParams.entries()) {
req.expect.containsQueryParam(key, value);
if (queryMap.has(key)) {
const existing = queryMap.get(key)!;
if (Array.isArray(existing)) {
existing.push(value);
} else {
queryMap.set(key, [existing, value]);
}
} else {
queryMap.set(key, value);
}
}
for (const [key, value] of queryMap.entries()) {
if (Array.isArray(value)) {
req.expect.containsQueryParam(key, value, "multi");
} else {
req.expect.containsQueryParam(key, value);
}
}
for (const param of Object.keys(req.query)) {
if (!url.searchParams.has(param)) {
Expand Down

0 comments on commit 5caa913

Please sign in to comment.