mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-24 16:32:29 +00:00
refactor(test): dedupe setup wizard helpers
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
resolveSetupWizardAllowFromEntries,
|
||||
resolveSetupWizardGroupAllowlist,
|
||||
} from "../../../test/helpers/extensions/setup-wizard.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js";
|
||||
import {
|
||||
@@ -1456,10 +1460,9 @@ describe("createAccountScopedAllowFromSection", () => {
|
||||
|
||||
expect(section.credentialInputKey).toBe("token");
|
||||
await expect(
|
||||
section.resolveEntries({
|
||||
cfg: {},
|
||||
resolveSetupWizardAllowFromEntries({
|
||||
resolveEntries: section.resolveEntries,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
credentialValues: {},
|
||||
entries: ["alice"],
|
||||
}),
|
||||
).resolves.toEqual([{ input: "alice", resolved: true, id: "ALICE" }]);
|
||||
@@ -1496,10 +1499,9 @@ describe("createAllowFromSection", () => {
|
||||
|
||||
expect(section.helpTitle).toBe("LINE allowlist");
|
||||
await expect(
|
||||
section.resolveEntries({
|
||||
cfg: {},
|
||||
resolveSetupWizardAllowFromEntries({
|
||||
resolveEntries: section.resolveEntries,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
credentialValues: {},
|
||||
entries: ["u1"],
|
||||
}),
|
||||
).resolves.toEqual([{ input: "u1", resolved: true, id: "U1" }]);
|
||||
@@ -1546,10 +1548,9 @@ describe("createAccountScopedGroupAccessSection", () => {
|
||||
expect(policyNext.channels?.slack?.groupPolicy).toBe("open");
|
||||
|
||||
await expect(
|
||||
section.resolveAllowlist?.({
|
||||
cfg: {},
|
||||
resolveSetupWizardGroupAllowlist({
|
||||
resolveAllowlist: section.resolveAllowlist,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
credentialValues: {},
|
||||
entries: ["general"],
|
||||
prompter,
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
promptSetupWizardAllowFrom,
|
||||
resolveSetupWizardAllowFromEntries,
|
||||
resolveSetupWizardGroupAllowlist,
|
||||
runSetupWizardFinalize,
|
||||
runSetupWizardPrepare,
|
||||
} from "../../../test/helpers/extensions/setup-wizard.js";
|
||||
import {
|
||||
createAllowlistSetupWizardProxy,
|
||||
createDelegatedFinalize,
|
||||
@@ -46,15 +53,7 @@ describe("createDelegatedPrepare", () => {
|
||||
|
||||
const prepare = createDelegatedPrepare(loadWizard);
|
||||
|
||||
expect(
|
||||
await prepare({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
runtime: {} as never,
|
||||
prompter: {} as never,
|
||||
}),
|
||||
).toEqual({
|
||||
expect(await runSetupWizardPrepare({ prepare })).toEqual({
|
||||
cfg: {
|
||||
channels: {
|
||||
demo: { enabled: true },
|
||||
@@ -88,16 +87,7 @@ describe("createDelegatedFinalize", () => {
|
||||
|
||||
const finalize = createDelegatedFinalize(loadWizard);
|
||||
|
||||
expect(
|
||||
await finalize({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
runtime: {} as never,
|
||||
prompter: {} as never,
|
||||
forceAllowFrom: true,
|
||||
}),
|
||||
).toEqual({
|
||||
expect(await runSetupWizardFinalize({ finalize, forceAllowFrom: true })).toEqual({
|
||||
cfg: {
|
||||
channels: {
|
||||
demo: { forceAllowFrom: true },
|
||||
@@ -159,27 +149,18 @@ describe("createAllowlistSetupWizardProxy", () => {
|
||||
});
|
||||
|
||||
expect(
|
||||
await wizard.dmPolicy?.promptAllowFrom?.({
|
||||
cfg: {},
|
||||
prompter: {} as never,
|
||||
accountId: "default",
|
||||
}),
|
||||
await promptSetupWizardAllowFrom({ promptAllowFrom: wizard.dmPolicy?.promptAllowFrom }),
|
||||
).toEqual({});
|
||||
expect(
|
||||
await wizard.allowFrom?.resolveEntries({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
await resolveSetupWizardAllowFromEntries({
|
||||
resolveEntries: wizard.allowFrom?.resolveEntries,
|
||||
entries: ["alice"],
|
||||
}),
|
||||
).toEqual([{ input: "alice", resolved: false, id: null }]);
|
||||
expect(
|
||||
await wizard.groupAccess?.resolveAllowlist?.({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
await resolveSetupWizardGroupAllowlist({
|
||||
resolveAllowlist: wizard.groupAccess?.resolveAllowlist,
|
||||
entries: ["general"],
|
||||
prompter: {} as never,
|
||||
}),
|
||||
).toEqual([{ input: "general" }]);
|
||||
});
|
||||
@@ -231,31 +212,14 @@ describe("createDelegatedSetupWizardProxy", () => {
|
||||
expect(await wizard.status.resolveStatusLines?.({ cfg: {}, configured: false })).toEqual([
|
||||
"line",
|
||||
]);
|
||||
expect(
|
||||
await wizard.prepare?.({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
runtime: {} as never,
|
||||
prompter: {} as never,
|
||||
}),
|
||||
).toEqual({
|
||||
expect(await runSetupWizardPrepare({ prepare: wizard.prepare })).toEqual({
|
||||
cfg: {
|
||||
channels: {
|
||||
demo: { prepared: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(
|
||||
await wizard.finalize?.({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
runtime: {} as never,
|
||||
prompter: {} as never,
|
||||
forceAllowFrom: false,
|
||||
}),
|
||||
).toEqual({
|
||||
expect(await runSetupWizardFinalize({ finalize: wizard.finalize })).toEqual({
|
||||
cfg: {
|
||||
channels: {
|
||||
demo: { finalized: true },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runSetupWizardFinalize } from "../../test/helpers/extensions/setup-wizard.js";
|
||||
import { createOptionalChannelSetupSurface } from "./channel-setup.js";
|
||||
|
||||
describe("createOptionalChannelSetupSurface", () => {
|
||||
@@ -21,17 +22,13 @@ describe("createOptionalChannelSetupSurface", () => {
|
||||
expect(setup.setupWizard.channel).toBe("example");
|
||||
expect(setup.setupWizard.status.unconfiguredHint).toContain("/channels/example");
|
||||
await expect(
|
||||
setup.setupWizard.finalize?.({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
credentialValues: {},
|
||||
runSetupWizardFinalize({
|
||||
finalize: setup.setupWizard.finalize,
|
||||
runtime: {
|
||||
log: () => {},
|
||||
error: () => {},
|
||||
exit: async () => {},
|
||||
},
|
||||
prompter: {} as never,
|
||||
forceAllowFrom: false,
|
||||
}),
|
||||
).rejects.toThrow("@openclaw/example");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user