import { createClientConfigDoc, getClientConfig, getClientDisplayName, } from "../clientsConfig.getters"; import { createClientConfig } from "../../../test-utils/factories"; describe("db.clientsConfig", () => { describe("getClientConfig", () => { it("should return client config by clientId", async () => { const clientId = "test-client-id"; const clientConfig = createClientConfig({ clientId, language: "Hebrew", products: { feature1: true, feature2: false } as any, }); await createClientConfigDoc(clientConfig); const result = await getClientConfig(clientId); expect(result).toMatchObject({ clientId, language: "Hebrew", products: { feature1: true, feature2: false }, }); }); it("should support websiteTalk product config", async () => { const clientId = "websiteTalk-test"; const clientConfig = createClientConfig({ clientId, products: { websiteTalk: { companyName: "Acme Ltd", timezone: "Asia/Jerusalem", language: "he", }, }, }); await createClientConfigDoc(clientConfig); const result = await getClientConfig(clientId); expect(result).toMatchObject({ clientId, products: { websiteTalk: { companyName: "Acme Ltd", timezone: "Asia/Jerusalem", language: "he", }, }, }); }); it("should return null for non-existent clientId", async () => { const result = await getClientConfig("non-existent-client"); expect(result).toBeNull(); }); it("should return quota.clientDisplayName when set on client config", async () => { const clientId = "display-name-client"; await createClientConfigDoc( createClientConfig({ clientId, quota: { totalQuota: 100, usedQuota: 0, clientDisplayName: "Acme Corp" }, }), ); expect(await getClientDisplayName(clientId)).toBe("Acme Corp"); }); it("should return '-' when quota.clientDisplayName is missing", async () => { const clientId = "no-display-name-client"; await createClientConfigDoc( createClientConfig({ clientId, quota: { totalQuota: 100, usedQuota: 0 } }), ); expect(await getClientDisplayName(clientId)).toBe("-"); }); it("should return '-' when client config is missing", async () => { expect(await getClientDisplayName("missing-client")).toBe("-"); }); it("given moked_106 with both toolsPrompts when saved and retrieved then both prompts are persisted", async () => { // Given const clientId = "tools-prompts-both"; const clientConfig = createClientConfig({ clientId, products: { municipal: { cityName: "ashdod", timezone: "Asia/Jerusalem", moked_106: { toolsPrompts: { findSubjectsSystemPrompt: "Custom subjects prompt", findStreetsSystemPrompt: "Custom streets prompt", }, }, }, }, }); // When await createClientConfigDoc(clientConfig); const result = await getClientConfig(clientId); // Then expect(result?.products.municipal?.moked_106?.toolsPrompts).toMatchObject( { findSubjectsSystemPrompt: "Custom subjects prompt", findStreetsSystemPrompt: "Custom streets prompt", }, ); }); it("given moked_106 with findSubjectsSystemPrompt only when saved and retrieved then findStreetsSystemPrompt is undefined", async () => { // Given const clientId = "tools-prompts-subjects-only"; const clientConfig = createClientConfig({ clientId, products: { municipal: { cityName: "ashdod", timezone: "Asia/Jerusalem", moked_106: { toolsPrompts: { findSubjectsSystemPrompt: "Subjects only prompt", }, }, }, }, }); // When await createClientConfigDoc(clientConfig); const result = await getClientConfig(clientId); // Then expect( result?.products.municipal?.moked_106?.toolsPrompts ?.findSubjectsSystemPrompt, ).toBe("Subjects only prompt"); expect( result?.products.municipal?.moked_106?.toolsPrompts ?.findStreetsSystemPrompt, ).toBeUndefined(); }); it("given moked_106 without toolsPrompts when saved and retrieved then toolsPrompts is undefined", async () => { // Given const clientId = "tools-prompts-absent"; const clientConfig = createClientConfig({ clientId, products: { municipal: { cityName: "ashdod", timezone: "Asia/Jerusalem", moked_106: { avoidSaveTickets: true, }, }, }, }); // When await createClientConfigDoc(clientConfig); const result = await getClientConfig(clientId); // Then expect( result?.products.municipal?.moked_106?.toolsPrompts, ).toBeUndefined(); }); it("should support communications config", async () => { const clientId = "communications-test"; const clientConfig = createClientConfig({ clientId, communications: { sendGrid: { emailTo: ["test@example.com"], templateId: "temp-123", senderId: "sender-123", }, sms: {}, whatsapp: {}, }, }); await createClientConfigDoc(clientConfig); const result = await getClientConfig(clientId); expect(result).toMatchObject({ clientId, communications: { sendGrid: { emailTo: ["test@example.com"], templateId: "temp-123", senderId: "sender-123", }, sms: {}, whatsapp: {}, }, }); }); }); });