From 71a20422a0d2a663ce3bb4fd162bd877003b7131 Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 8 May 2026 19:14:39 +0100 Subject: [PATCH] test: tighten zalo setup assertions --- extensions/zalo/src/setup-surface.test.ts | 39 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/extensions/zalo/src/setup-surface.test.ts b/extensions/zalo/src/setup-surface.test.ts index baa75346eb1..856963f292b 100644 --- a/extensions/zalo/src/setup-surface.test.ts +++ b/extensions/zalo/src/setup-surface.test.ts @@ -60,9 +60,14 @@ describe("zalo setup wizard", () => { }); expect(result.accountId).toBe("default"); - expect(result.cfg.channels?.zalo?.enabled).toBe(true); - expect(result.cfg.channels?.zalo?.botToken).toBe("12345689:abc-xyz"); - expect(result.cfg.channels?.zalo?.webhookUrl).toBeUndefined(); + const zaloConfig = result.cfg.channels?.zalo; + expect(zaloConfig).toBeDefined(); + if (!zaloConfig) { + throw new Error("expected Zalo config"); + } + expect(zaloConfig.enabled).toBe(true); + expect(zaloConfig.botToken).toBe("12345689:abc-xyz"); + expect(zaloConfig.webhookUrl).toBeUndefined(); }); it("reads the named-account DM policy instead of the channel root", () => { @@ -117,11 +122,20 @@ describe("zalo setup wizard", () => { }); const next = zaloDmPolicy.setPolicy(cfg, "open"); - expect(next.channels?.zalo?.dmPolicy).toBe("disabled"); + const zaloConfig = next.channels?.zalo; + expect(zaloConfig).toBeDefined(); + if (!zaloConfig) { + throw new Error("expected Zalo config"); + } + expect(zaloConfig.dmPolicy).toBe("disabled"); const workAccount = next.channels?.zalo?.accounts?.work as | { dmPolicy?: string; allowFrom?: Array } | undefined; - expect(workAccount?.dmPolicy).toBe("open"); + expect(workAccount).toBeDefined(); + if (!workAccount) { + throw new Error("expected Zalo work account"); + } + expect(workAccount.dmPolicy).toBe("open"); }); it('writes open policy state to the named account and preserves inherited allowFrom with "*"', () => { @@ -142,12 +156,21 @@ describe("zalo setup wizard", () => { "work", ); - expect(next.channels?.zalo?.dmPolicy).toBeUndefined(); + const zaloConfig = next.channels?.zalo; + expect(zaloConfig).toBeDefined(); + if (!zaloConfig) { + throw new Error("expected Zalo config"); + } + expect(zaloConfig.dmPolicy).toBeUndefined(); const workAccount = next.channels?.zalo?.accounts?.work as | { dmPolicy?: string; allowFrom?: Array } | undefined; - expect(workAccount?.dmPolicy).toBe("open"); - expect(workAccount?.allowFrom).toEqual(["123456789", "*"]); + expect(workAccount).toBeDefined(); + if (!workAccount) { + throw new Error("expected Zalo work account"); + } + expect(workAccount.dmPolicy).toBe("open"); + expect(workAccount.allowFrom).toEqual(["123456789", "*"]); }); it("uses configured defaultAccount for omitted setup configured state", async () => {