From 23279d1e41b87875d1b8eea47e640cb8d0908211 Mon Sep 17 00:00:00 2001 From: Chenjie Shi <tadelesh.shi@live.cn> Date: Thu, 10 Oct 2024 10:58:10 +0800 Subject: [PATCH] fix explode query check of mockapi for routes test case (#742) * fix explode query check in routes test case * changeset --- .changeset/thin-radios-help.md | 5 +++++ .../cadl-ranch-specs/http/routes/mockapi.ts | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changeset/thin-radios-help.md diff --git a/.changeset/thin-radios-help.md b/.changeset/thin-radios-help.md new file mode 100644 index 000000000..73a9100e2 --- /dev/null +++ b/.changeset/thin-radios-help.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": patch +--- + +fix explode query check of mockapi for routes test case diff --git a/packages/cadl-ranch-specs/http/routes/mockapi.ts b/packages/cadl-ranch-specs/http/routes/mockapi.ts index b422eb319..ab09373eb 100644 --- a/packages/cadl-ranch-specs/http/routes/mockapi.ts +++ b/packages/cadl-ranch-specs/http/routes/mockapi.ts @@ -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)) {