Skip to content

Commit

Permalink
fix explode query check of mockapi for routes test case (#742)
Browse files Browse the repository at this point in the history
* fix explode query check in routes test case

* changeset
  • Loading branch information
tadelesh authored Oct 10, 2024
1 parent fbd34bd commit 23279d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thin-radios-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

fix explode query check of mockapi for routes test case
19 changes: 18 additions & 1 deletion packages/cadl-ranch-specs/http/routes/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@ function defineUri(uri: string) {
const url = new URL("http://example.com" + uri);
return passOnSuccess(
mockapi.get(url.pathname, (req) => {
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 23279d1

Please sign in to comment.