Skip to content

Commit

Permalink
specs, back port microsoft/typespec#4713 (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Oct 15, 2024
1 parent 9df792d commit a984aa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-falcons-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Back port fix on route mockapi.
31 changes: 13 additions & 18 deletions packages/cadl-ranch-specs/http/routes/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,29 @@ export const Scenarios: Record<string, ScenarioMockApi> = {};

function createTests(uri: string) {
const url = new URL("http://example.com" + uri);
const searchParams = url.searchParams;
const params: Record<string, any> = {};
for (const [key, value] of searchParams) {
params[key] = value;
const queryMap = new Map<string, string | string[]>();
for (const [key, value] of url.searchParams.entries()) {
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);
}
}
return passOnSuccess({
uri: url.pathname,
method: "get",
request: {
params,
params: Object.fromEntries(queryMap),
},
response: {
status: 204,
},
handler: (req: MockRequest) => {
const queryMap = new Map<string, string | string[]>();
for (const [key, value] of url.searchParams.entries()) {
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");
Expand Down

0 comments on commit a984aa0

Please sign in to comment.