mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
feat(tokenplan): 更新 AccountIds 参数处理逻辑
修改 `assign-seats` 命令中的 AccountIds 参数处理,将字符串类型的 AccountIds 转换为数组。同时,更新相关的测试用例以验证新逻辑的正确性。
This commit is contained in:
@@ -165,7 +165,7 @@ function buildQueryParams(
|
||||
if (Array.isArray(accountIds) && accountIds.length > 0) {
|
||||
params.AccountIds = accountIds;
|
||||
} else if (typeof accountIds === "string" && accountIds.length > 0) {
|
||||
params.AccountIds = accountIds;
|
||||
params.AccountIds = [accountIds];
|
||||
}
|
||||
|
||||
return params;
|
||||
|
||||
@@ -328,6 +328,8 @@ describe("e2e: tokenplan dry-run", () => {
|
||||
expect(data.query?.WorkspaceId).toBe("ws_456");
|
||||
expect(data.query?.SeatType).toBe("standard");
|
||||
expect(data.query?.AccountIds).toEqual(["acc_1", "acc_2"]);
|
||||
expect(data.endpoint).toMatch(/AccountIds\.1=acc_1/);
|
||||
expect(data.endpoint).toMatch(/AccountIds\.2=acc_2/);
|
||||
});
|
||||
|
||||
test("add-member --dry-run 输出 endpoint 和 query 参数", async () => {
|
||||
|
||||
@@ -28,9 +28,9 @@ export function buildCanonicalQuery(params: Record<string, string | string[] | u
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (value === undefined || value === "") continue;
|
||||
if (Array.isArray(value)) {
|
||||
const sorted = [...value].sort();
|
||||
for (const v of sorted) {
|
||||
if (v !== "") pairs.push([key, v]);
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const v = value[i];
|
||||
if (v !== "") pairs.push([`${key}.${i + 1}`, v]);
|
||||
}
|
||||
} else {
|
||||
pairs.push([key, value]);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { expect, test } from "vite-plus/test";
|
||||
import { buildCanonicalQuery } from "../src/client/ak-sign.ts";
|
||||
|
||||
test("buildCanonicalQuery flattens arrays as indexed keys", () => {
|
||||
expect(
|
||||
buildCanonicalQuery({
|
||||
WorkspaceId: "ws_1",
|
||||
SeatType: "pro",
|
||||
AccountIds: ["acc_1", "acc_2"],
|
||||
}),
|
||||
).toBe("AccountIds.1=acc_1&AccountIds.2=acc_2&SeatType=pro&WorkspaceId=ws_1");
|
||||
});
|
||||
|
||||
test("buildCanonicalQuery uses single indexed key for one-element arrays", () => {
|
||||
expect(
|
||||
buildCanonicalQuery({
|
||||
AccountIds: ["acc_2bd88814c31743d9aa5833dc16b3b8e0"],
|
||||
}),
|
||||
).toBe("AccountIds.1=acc_2bd88814c31743d9aa5833dc16b3b8e0");
|
||||
});
|
||||
Reference in New Issue
Block a user