Skip to content

Commit 1590e69

Browse files
author
wb-liuxuehuan
committed
feat(tokenplan): 更新 AccountIds 参数处理逻辑
修改 `assign-seats` 命令中的 AccountIds 参数处理,将字符串类型的 AccountIds 转换为数组。同时,更新相关的测试用例以验证新逻辑的正确性。
1 parent d74686f commit 1590e69

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

packages/cli/src/commands/tokenplan/assign-seats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function buildQueryParams(
165165
if (Array.isArray(accountIds) && accountIds.length > 0) {
166166
params.AccountIds = accountIds;
167167
} else if (typeof accountIds === "string" && accountIds.length > 0) {
168-
params.AccountIds = accountIds;
168+
params.AccountIds = [accountIds];
169169
}
170170

171171
return params;

packages/cli/tests/e2e/tokenplan.e2e.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ describe("e2e: tokenplan dry-run", () => {
328328
expect(data.query?.WorkspaceId).toBe("ws_456");
329329
expect(data.query?.SeatType).toBe("standard");
330330
expect(data.query?.AccountIds).toEqual(["acc_1", "acc_2"]);
331+
expect(data.endpoint).toMatch(/AccountIds\.1=acc_1/);
332+
expect(data.endpoint).toMatch(/AccountIds\.2=acc_2/);
331333
});
332334

333335
test("add-member --dry-run 输出 endpoint 和 query 参数", async () => {

packages/core/src/client/ak-sign.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export function buildCanonicalQuery(params: Record<string, string | string[] | u
2828
for (const [key, value] of Object.entries(params)) {
2929
if (value === undefined || value === "") continue;
3030
if (Array.isArray(value)) {
31-
const sorted = [...value].sort();
32-
for (const v of sorted) {
33-
if (v !== "") pairs.push([key, v]);
31+
for (let i = 0; i < value.length; i++) {
32+
const v = value[i];
33+
if (v !== "") pairs.push([`${key}.${i + 1}`, v]);
3434
}
3535
} else {
3636
pairs.push([key, value]);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect, test } from "vite-plus/test";
2+
import { buildCanonicalQuery } from "../src/client/ak-sign.ts";
3+
4+
test("buildCanonicalQuery flattens arrays as indexed keys", () => {
5+
expect(
6+
buildCanonicalQuery({
7+
WorkspaceId: "ws_1",
8+
SeatType: "pro",
9+
AccountIds: ["acc_1", "acc_2"],
10+
}),
11+
).toBe("AccountIds.1=acc_1&AccountIds.2=acc_2&SeatType=pro&WorkspaceId=ws_1");
12+
});
13+
14+
test("buildCanonicalQuery uses single indexed key for one-element arrays", () => {
15+
expect(
16+
buildCanonicalQuery({
17+
AccountIds: ["acc_2bd88814c31743d9aa5833dc16b3b8e0"],
18+
}),
19+
).toBe("AccountIds.1=acc_2bd88814c31743d9aa5833dc16b3b8e0");
20+
});

0 commit comments

Comments
 (0)