import { AI_REVIEW_SUBJECT, isServiceOrCasePath, type WhatsAppContexts, whatsAppSubjectForPath, } from "./whatsapp"; /** * Testes de caminhos-base de whatsAppSubjectForPath e isServiceOrCasePath (complemento de whatsapp.test.ts): * o case sem tabela de nomes, as duas tabelas independentes, nome vazio e rotas sem slug. */ const contexts: WhatsAppContexts = { services: { "criacao-de-sites": "Sites profissionais" }, cases: { "sev-modaintima": "SEV Moda Íntima", vazio: "" }, }; describe("whatsAppSubjectForPath", () => { it("path: /cases/ without contexts -> undefined", () => { expect(whatsAppSubjectForPath("/cases/sev-modaintima")).toBeUndefined(); expect( whatsAppSubjectForPath("/cases/sev-modaintima", undefined), ).toBeUndefined(); }); it("path: /ia without contexts and with a trailing slash -> the AI review", () => { expect(whatsAppSubjectForPath("/ia")).toBe(AI_REVIEW_SUBJECT); expect(whatsAppSubjectForPath("/ia/", contexts)).toBe(AI_REVIEW_SUBJECT); }); it("path: a service slug is only looked up in the services, a case id only in the cases", () => { expect( whatsAppSubjectForPath("/servicos/sev-modaintima", contexts), ).toBeUndefined(); expect( whatsAppSubjectForPath("/cases/criacao-de-sites", contexts), ).toBeUndefined(); }); it("path: a case with an empty name -> no subject (the message stays generic)", () => { expect(whatsAppSubjectForPath("/cases/vazio", contexts)).toBeUndefined(); }); it.each([ "", "/servicos/", "/cases/", "/ia/extra", "/IA", "/cases/sev-modaintima/extra", ])("path: %j -> no subject", (pathname) => { expect(whatsAppSubjectForPath(pathname, contexts)).toBeUndefined(); }); }); describe("isServiceOrCasePath", () => { it.each(["", "/servicos/", "/cases/", "/cases/a/b", "/curriculo", "/ia/"])( "path: %j -> false", (pathname) => { expect(isServiceOrCasePath(pathname)).toBe(false); }, ); });