From 330b9895c106538311d6f4bd661827f6230ab13f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 04:32:54 +0100 Subject: [PATCH] test(matrix): share onboarding config fixtures --- .../matrix/src/onboarding.test-harness.ts | 49 ++++++++++++ extensions/matrix/src/onboarding.test.ts | 74 +++---------------- 2 files changed, 59 insertions(+), 64 deletions(-) diff --git a/extensions/matrix/src/onboarding.test-harness.ts b/extensions/matrix/src/onboarding.test-harness.ts index bc689d9c68f..233620199c1 100644 --- a/extensions/matrix/src/onboarding.test-harness.ts +++ b/extensions/matrix/src/onboarding.test-harness.ts @@ -156,3 +156,52 @@ export async function runMatrixAddAccountAllowlistConfigure(params: { configured: true, }); } + +export function createConfiguredMatrixDefaultAccountConfig(): CoreConfig { + return { + channels: { + matrix: { + accounts: { + default: { + homeserver: "https://matrix.main.example.org", + accessToken: "main-token", + }, + }, + }, + }, + } as CoreConfig; +} + +export function createLegacyMatrixTopLevelConfig(): CoreConfig { + return { + channels: { + matrix: { + homeserver: "https://matrix.main.example.org", + userId: "@main:example.org", + accessToken: "main-token", + avatarUrl: "mxc://matrix.main.example.org/main-avatar", + }, + }, + } as CoreConfig; +} + +export function createMatrixTokenAddAccountPrompter(params?: { + accountName?: string; + homeserver?: string; + accessToken?: string; + deviceName?: string; +}) { + return createMatrixWizardPrompter({ + select: { + "Matrix already configured. What do you want to do?": "add-account", + "Matrix auth method": "token", + }, + text: { + "Matrix account name": params?.accountName ?? "ops", + "Matrix homeserver URL": params?.homeserver ?? "https://matrix.ops.example.org", + "Matrix access token": params?.accessToken ?? "ops-token", + "Matrix device name (optional)": params?.deviceName ?? "", + }, + onConfirm: async () => false, + }); +} diff --git a/extensions/matrix/src/onboarding.test.ts b/extensions/matrix/src/onboarding.test.ts index aaa0c4f8e31..13a7802711b 100644 --- a/extensions/matrix/src/onboarding.test.ts +++ b/extensions/matrix/src/onboarding.test.ts @@ -1,6 +1,9 @@ import { describe, expect, it, vi } from "vitest"; import { matrixOnboardingAdapter } from "./onboarding.js"; import { + createConfiguredMatrixDefaultAccountConfig, + createLegacyMatrixTopLevelConfig, + createMatrixTokenAddAccountPrompter, installMatrixOnboardingEnvRestoreHooks, createMatrixWizardPrompter, runMatrixAddAccountAllowlistConfigure, @@ -43,18 +46,7 @@ describe("matrix onboarding", () => { }); const result = await runMatrixInteractiveConfigure({ - cfg: { - channels: { - matrix: { - accounts: { - default: { - homeserver: "https://matrix.main.example.org", - accessToken: "main-token", - }, - }, - }, - }, - } as CoreConfig, + cfg: createConfiguredMatrixDefaultAccountConfig(), prompter, shouldPromptAccountIds: true, configured: true, @@ -116,18 +108,7 @@ describe("matrix onboarding", () => { }); const result = await runMatrixInteractiveConfigure({ - cfg: { - channels: { - matrix: { - accounts: { - default: { - homeserver: "https://matrix.main.example.org", - accessToken: "main-token", - }, - }, - }, - }, - } as CoreConfig, + cfg: createConfiguredMatrixDefaultAccountConfig(), prompter, shouldPromptAccountIds: true, configured: true, @@ -154,31 +135,10 @@ describe("matrix onboarding", () => { it("promotes legacy top-level Matrix config before adding a named account", async () => { installMatrixTestRuntime(); - const prompter = createMatrixWizardPrompter({ - select: { - "Matrix already configured. What do you want to do?": "add-account", - "Matrix auth method": "token", - }, - text: { - "Matrix account name": "ops", - "Matrix homeserver URL": "https://matrix.ops.example.org", - "Matrix access token": "ops-token", - "Matrix device name (optional)": "", - }, - onConfirm: async () => false, - }); + const prompter = createMatrixTokenAddAccountPrompter(); const result = await runMatrixInteractiveConfigure({ - cfg: { - channels: { - matrix: { - homeserver: "https://matrix.main.example.org", - userId: "@main:example.org", - accessToken: "main-token", - avatarUrl: "mxc://matrix.main.example.org/main-avatar", - }, - }, - } as CoreConfig, + cfg: createLegacyMatrixTopLevelConfig(), prompter, shouldPromptAccountIds: true, configured: true, @@ -208,28 +168,14 @@ describe("matrix onboarding", () => { it("reuses an existing raw default-like key during onboarding promotion when defaultAccount is unset", async () => { installMatrixTestRuntime(); - const prompter = createMatrixWizardPrompter({ - select: { - "Matrix already configured. What do you want to do?": "add-account", - "Matrix auth method": "token", - }, - text: { - "Matrix account name": "ops", - "Matrix homeserver URL": "https://matrix.ops.example.org", - "Matrix access token": "ops-token", - "Matrix device name (optional)": "", - }, - onConfirm: async () => false, - }); + const prompter = createMatrixTokenAddAccountPrompter(); const result = await runMatrixInteractiveConfigure({ cfg: { + ...createLegacyMatrixTopLevelConfig(), channels: { matrix: { - homeserver: "https://matrix.main.example.org", - userId: "@main:example.org", - accessToken: "main-token", - avatarUrl: "mxc://matrix.main.example.org/main-avatar", + ...createLegacyMatrixTopLevelConfig().channels?.matrix, accounts: { Default: { enabled: true,