From 758a5f1eda7ff4648a69fbde8a486fcad57428ff Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 00:37:09 +0100 Subject: [PATCH] test: tighten matrix doctor assertions --- extensions/matrix/src/doctor.test.ts | 63 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/extensions/matrix/src/doctor.test.ts b/extensions/matrix/src/doctor.test.ts index 44529c1c3c8..203aadbc718 100644 --- a/extensions/matrix/src/doctor.test.ts +++ b/extensions/matrix/src/doctor.test.ts @@ -57,6 +57,10 @@ describe("matrix doctor", () => { }); } + function expectChangeContaining(changes: readonly string[], fragment: string): void { + expect(changes.some((change) => change.includes(fragment))).toBe(true); + } + it("formats state and crypto previews", () => { expect( formatMatrixLegacyStatePreview({ @@ -203,11 +207,11 @@ describe("matrix doctor", () => { expect(workAccount?.rooms?.["!legacy:example.org"]).toEqual({ enabled: false, }); - expect(result.changes).toEqual( - expect.arrayContaining([ - "Moved channels.matrix.groups.!ops:example.org.allow → channels.matrix.groups.!ops:example.org.enabled (true).", - "Moved channels.matrix.accounts.work.rooms.!legacy:example.org.allow → channels.matrix.accounts.work.rooms.!legacy:example.org.enabled (false).", - ]), + expect(result.changes).toContain( + "Moved channels.matrix.groups.!ops:example.org.allow → channels.matrix.groups.!ops:example.org.enabled (true).", + ); + expect(result.changes).toContain( + "Moved channels.matrix.accounts.work.rooms.!legacy:example.org.allow → channels.matrix.accounts.work.rooms.!legacy:example.org.enabled (false).", ); }); @@ -245,11 +249,11 @@ describe("matrix doctor", () => { expect(workAccount?.network).toEqual({ dangerouslyAllowPrivateNetwork: false, }); - expect(result.changes).toEqual( - expect.arrayContaining([ - "Moved channels.matrix.allowPrivateNetwork → channels.matrix.network.dangerouslyAllowPrivateNetwork (true).", - "Moved channels.matrix.accounts.work.allowPrivateNetwork → channels.matrix.accounts.work.network.dangerouslyAllowPrivateNetwork (false).", - ]), + expect(result.changes).toContain( + "Moved channels.matrix.allowPrivateNetwork → channels.matrix.network.dangerouslyAllowPrivateNetwork (true).", + ); + expect(result.changes).toContain( + "Moved channels.matrix.accounts.work.allowPrivateNetwork → channels.matrix.accounts.work.network.dangerouslyAllowPrivateNetwork (false).", ); }); @@ -274,12 +278,11 @@ describe("matrix doctor", () => { expect(matrixDm?.policy).toBe("allowlist"); expect(matrixDm?.allowFrom).toEqual(["@alice:example.org", "@bob:example.org"]); - expect(result.changes).toEqual( - expect.arrayContaining([ - expect.stringContaining('Migrated channels.matrix.dm.policy "trusted" → "allowlist"'), - expect.stringContaining("preserved 2 channels.matrix.dm.allowFrom entries"), - ]), + expectChangeContaining( + result.changes, + 'Migrated channels.matrix.dm.policy "trusted" → "allowlist"', ); + expectChangeContaining(result.changes, "preserved 2 channels.matrix.dm.allowFrom entries"); }); it("migrates legacy 'trusted' policy with whitespace-only allowFrom entries to 'pairing'", () => { @@ -295,10 +298,9 @@ describe("matrix doctor", () => { const matrixDm = (result.config.channels?.matrix as { dm?: { policy?: string } })?.dm; expect(matrixDm?.policy).toBe("pairing"); - expect(result.changes).toEqual( - expect.arrayContaining([ - expect.stringContaining('Migrated channels.matrix.dm.policy "trusted" → "pairing"'), - ]), + expectChangeContaining( + result.changes, + 'Migrated channels.matrix.dm.policy "trusted" → "pairing"', ); }); @@ -310,10 +312,9 @@ describe("matrix doctor", () => { const matrixDm = (result.config.channels?.matrix as { dm?: { policy?: string } })?.dm; expect(matrixDm?.policy).toBe("pairing"); - expect(result.changes).toEqual( - expect.arrayContaining([ - expect.stringContaining('Migrated channels.matrix.dm.policy "trusted" → "pairing"'), - ]), + expectChangeContaining( + result.changes, + 'Migrated channels.matrix.dm.policy "trusted" → "pairing"', ); }); @@ -351,15 +352,13 @@ describe("matrix doctor", () => { expect(accounts?.work?.dm?.policy).toBe("allowlist"); expect(accounts?.work?.dm?.allowFrom).toEqual(["@boss:example.org"]); expect(accounts?.personal?.dm?.policy).toBe("pairing"); - expect(result.changes).toEqual( - expect.arrayContaining([ - expect.stringContaining( - 'Migrated channels.matrix.accounts.work.dm.policy "trusted" → "allowlist"', - ), - expect.stringContaining( - 'Migrated channels.matrix.accounts.personal.dm.policy "trusted" → "pairing"', - ), - ]), + expectChangeContaining( + result.changes, + 'Migrated channels.matrix.accounts.work.dm.policy "trusted" → "allowlist"', + ); + expectChangeContaining( + result.changes, + 'Migrated channels.matrix.accounts.personal.dm.policy "trusted" → "pairing"', ); });