





















@@ -15,8 +15,18 @@ function applyOpsAccountConfig(cfg: CoreConfig): CoreConfig {
1515}) as CoreConfig;
1616}
171718+function expectFields(value: unknown, expected: Record<string, unknown>): void {
19+if (value === undefined || value === null || typeof value !== "object" || Array.isArray(value)) {
20+throw new Error("expected object with fields");
21+}
22+const record = value as Record<string, unknown>;
23+Object.entries(expected).forEach(([key, expectedValue]) => {
24+expect(record[key]).toEqual(expectedValue);
25+});
26+}
27+1828function expectPromotedDefaultAccount(next: CoreConfig): void {
19-expect(next.channels?.matrix?.accounts?.Default).toMatchObject({
29+expectFields(next.channels?.matrix?.accounts?.Default, {
2030enabled: true,
2131deviceName: "Legacy raw key",
2232homeserver: "https://matrix.example.org",
@@ -28,7 +38,7 @@ function expectPromotedDefaultAccount(next: CoreConfig): void {
2838}
29393040function expectOpsAccount(next: CoreConfig): void {
31-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
41+expectFields(next.channels?.matrix?.accounts?.ops, {
3242name: "Ops",
3343enabled: true,
3444homeserver: "https://matrix.example.org",
@@ -125,7 +135,7 @@ describe("createMatrixSetupWizardProxy", () => {
125135expect(proxy.dmPolicy?.getCurrent(cfg, "ops")).toBe("pairing");
126136const next = proxy.dmPolicy?.setPolicy(cfg, "open", "ops") as CoreConfig;
127137128-expect(next.channels?.matrix?.accounts?.ops?.dm).toMatchObject({
138+expectFields(next.channels?.matrix?.accounts?.ops?.dm, {
129139policy: "open",
130140allowFrom: ["@ops:example.org", "*"],
131141});
@@ -160,7 +170,7 @@ describe("createMatrixSetupWizardProxy", () => {
160170161171const next = proxy.dmPolicy?.setPolicy(cfg, "allowlist", "ops") as CoreConfig;
162172163-expect(next.channels?.matrix?.accounts?.ops?.dm).toMatchObject({
173+expectFields(next.channels?.matrix?.accounts?.ops?.dm, {
164174policy: "allowlist",
165175allowFrom: ["@ops:example.org"],
166176});
@@ -195,13 +205,13 @@ describe("matrixSetupAdapter", () => {
195205expect(next.channels?.matrix?.homeserver).toBeUndefined();
196206expect(next.channels?.matrix?.userId).toBeUndefined();
197207expect(next.channels?.matrix?.accessToken).toBeUndefined();
198-expect(next.channels?.matrix?.accounts?.default).toMatchObject({
208+expectFields(next.channels?.matrix?.accounts?.default, {
199209homeserver: "https://matrix.example.org",
200210userId: "@default:example.org",
201211accessToken: "default-token",
202212deviceName: "Default device",
203213});
204-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
214+expectFields(next.channels?.matrix?.accounts?.ops, {
205215name: "Ops",
206216enabled: true,
207217homeserver: "https://matrix.example.org",
@@ -260,7 +270,7 @@ describe("matrixSetupAdapter", () => {
260270const next = applyOpsAccountConfig(cfg);
261271262272expectPromotedDefaultAccount(next);
263-expect(next.channels?.matrix?.accounts?.support).toMatchObject({
273+expectFields(next.channels?.matrix?.accounts?.support, {
264274homeserver: "https://matrix.example.org",
265275accessToken: "support-token",
266276});
@@ -296,7 +306,7 @@ describe("matrixSetupAdapter", () => {
296306},
297307}) as CoreConfig;
298308299-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
309+expectFields(next.channels?.matrix?.accounts?.ops, {
300310name: "Ops",
301311enabled: true,
302312});
@@ -334,7 +344,7 @@ describe("matrixSetupAdapter", () => {
334344},
335345}) as CoreConfig;
336346337-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
347+expectFields(next.channels?.matrix?.accounts?.ops, {
338348name: "Ops",
339349enabled: true,
340350avatarUrl: "mxc://example.org/ops-avatar",
@@ -354,7 +364,7 @@ describe("matrixSetupAdapter", () => {
354364},
355365}) as CoreConfig;
356366357-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
367+expectFields(next.channels?.matrix?.accounts?.ops, {
358368enabled: true,
359369homeserver: "https://matrix.example.org",
360370accessToken: "ops-token",
@@ -373,7 +383,7 @@ describe("matrixSetupAdapter", () => {
373383},
374384}) as CoreConfig;
375385376-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
386+expectFields(next.channels?.matrix?.accounts?.ops, {
377387enabled: true,
378388homeserver: "https://matrix.example.org",
379389accessToken: "ops-token",
@@ -406,7 +416,7 @@ describe("matrixSetupAdapter", () => {
406416},
407417}) as CoreConfig;
408418409-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
419+expectFields(next.channels?.matrix?.accounts?.ops, {
410420enabled: true,
411421homeserver: "http://matrix.internal:8008",
412422accessToken: "ops-token",
@@ -447,7 +457,7 @@ describe("matrixSetupAdapter", () => {
447457}) as CoreConfig;
448458449459expect(next.channels?.matrix?.blockStreaming).toBe(true);
450-expect(next.channels?.matrix?.accounts?.ops).toMatchObject({
460+expectFields(next.channels?.matrix?.accounts?.ops, {
451461name: "Ops",
452462enabled: true,
453463homeserver: "https://matrix.example.org",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。