refactor: centralize outbound target validation
This commit is contained in:
39
src/infra/outbound/targets.test.ts
Normal file
39
src/infra/outbound/targets.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveOutboundTarget } from "./targets.js";
|
||||
|
||||
describe("resolveOutboundTarget", () => {
|
||||
it("falls back to whatsapp allowFrom", () => {
|
||||
const res = resolveOutboundTarget({
|
||||
provider: "whatsapp",
|
||||
to: "",
|
||||
allowFrom: ["+1555"],
|
||||
});
|
||||
expect(res).toEqual({ ok: true, to: "+1555" });
|
||||
});
|
||||
|
||||
it("normalizes whatsapp target when provided", () => {
|
||||
const res = resolveOutboundTarget({
|
||||
provider: "whatsapp",
|
||||
to: " (555) 123-4567 ",
|
||||
});
|
||||
if (!res.ok) throw res.error;
|
||||
expect(res.to).toBe("+5551234567");
|
||||
});
|
||||
|
||||
it("rejects telegram with missing target", () => {
|
||||
const res = resolveOutboundTarget({ provider: "telegram", to: " " });
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.error.message).toContain("Telegram");
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects webchat delivery", () => {
|
||||
const res = resolveOutboundTarget({ provider: "webchat", to: "x" });
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.error.message).toContain("WebChat");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user