mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 13:07:28 +00:00
refactor(feishu): dedupe onboarding status env setup tests
This commit is contained in:
@@ -17,6 +17,44 @@ const baseStatusContext = {
|
||||
accountOverrides: {},
|
||||
};
|
||||
|
||||
async function withEnvVars(values: Record<string, string | undefined>, run: () => Promise<void>) {
|
||||
const previous = new Map<string, string | undefined>();
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
previous.set(key, process.env[key]);
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await run();
|
||||
} finally {
|
||||
for (const [key, prior] of previous.entries()) {
|
||||
if (prior === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = prior;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getStatusWithEnvRefs(params: { appIdKey: string; appSecretKey: string }) {
|
||||
return await feishuOnboardingAdapter.getStatus({
|
||||
cfg: {
|
||||
channels: {
|
||||
feishu: {
|
||||
appId: { source: "env", id: params.appIdKey, provider: "default" },
|
||||
appSecret: { source: "env", id: params.appSecretKey, provider: "default" },
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
...baseStatusContext,
|
||||
});
|
||||
}
|
||||
|
||||
describe("feishuOnboardingAdapter.configure", () => {
|
||||
it("does not throw when config appId/appSecret are SecretRef objects", async () => {
|
||||
const text = vi
|
||||
@@ -76,72 +114,30 @@ describe("feishuOnboardingAdapter.getStatus", () => {
|
||||
it("treats env SecretRef appId as not configured when env var is missing", async () => {
|
||||
const appIdKey = "FEISHU_APP_ID_STATUS_MISSING_TEST";
|
||||
const appSecretKey = "FEISHU_APP_SECRET_STATUS_MISSING_TEST";
|
||||
const prevAppId = process.env[appIdKey];
|
||||
const prevAppSecret = process.env[appSecretKey];
|
||||
delete process.env[appIdKey];
|
||||
process.env[appSecretKey] = "secret_env_456";
|
||||
|
||||
try {
|
||||
const status = await feishuOnboardingAdapter.getStatus({
|
||||
cfg: {
|
||||
channels: {
|
||||
feishu: {
|
||||
appId: { source: "env", id: appIdKey, provider: "default" },
|
||||
appSecret: { source: "env", id: appSecretKey, provider: "default" },
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
...baseStatusContext,
|
||||
});
|
||||
|
||||
expect(status.configured).toBe(false);
|
||||
} finally {
|
||||
if (prevAppId === undefined) {
|
||||
delete process.env[appIdKey];
|
||||
} else {
|
||||
process.env[appIdKey] = prevAppId;
|
||||
}
|
||||
if (prevAppSecret === undefined) {
|
||||
delete process.env[appSecretKey];
|
||||
} else {
|
||||
process.env[appSecretKey] = prevAppSecret;
|
||||
}
|
||||
}
|
||||
await withEnvVars(
|
||||
{
|
||||
[appIdKey]: undefined,
|
||||
[appSecretKey]: "secret_env_456",
|
||||
},
|
||||
async () => {
|
||||
const status = await getStatusWithEnvRefs({ appIdKey, appSecretKey });
|
||||
expect(status.configured).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("treats env SecretRef appId/appSecret as configured in status", async () => {
|
||||
const appIdKey = "FEISHU_APP_ID_STATUS_TEST";
|
||||
const appSecretKey = "FEISHU_APP_SECRET_STATUS_TEST";
|
||||
const prevAppId = process.env[appIdKey];
|
||||
const prevAppSecret = process.env[appSecretKey];
|
||||
process.env[appIdKey] = "cli_env_123";
|
||||
process.env[appSecretKey] = "secret_env_456";
|
||||
|
||||
try {
|
||||
const status = await feishuOnboardingAdapter.getStatus({
|
||||
cfg: {
|
||||
channels: {
|
||||
feishu: {
|
||||
appId: { source: "env", id: appIdKey, provider: "default" },
|
||||
appSecret: { source: "env", id: appSecretKey, provider: "default" },
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
...baseStatusContext,
|
||||
});
|
||||
|
||||
expect(status.configured).toBe(true);
|
||||
} finally {
|
||||
if (prevAppId === undefined) {
|
||||
delete process.env[appIdKey];
|
||||
} else {
|
||||
process.env[appIdKey] = prevAppId;
|
||||
}
|
||||
if (prevAppSecret === undefined) {
|
||||
delete process.env[appSecretKey];
|
||||
} else {
|
||||
process.env[appSecretKey] = prevAppSecret;
|
||||
}
|
||||
}
|
||||
await withEnvVars(
|
||||
{
|
||||
[appIdKey]: "cli_env_123",
|
||||
[appSecretKey]: "secret_env_456",
|
||||
},
|
||||
async () => {
|
||||
const status = await getStatusWithEnvRefs({ appIdKey, appSecretKey });
|
||||
expect(status.configured).toBe(true);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user