2025-11-24 17:23:59 +01:00
|
|
|
import { describe, expect, it } from "vitest";
|
2026-01-13 06:16:43 +00:00
|
|
|
import { assertWebChannel, normalizeE164, toWhatsappJid } from "./index.js";
|
2025-11-24 17:23:59 +01:00
|
|
|
|
|
|
|
|
describe("normalizeE164", () => {
|
2025-11-26 00:53:53 +01:00
|
|
|
it("strips whatsapp prefix and whitespace", () => {
|
2025-12-07 04:42:58 +00:00
|
|
|
expect(normalizeE164("whatsapp:+1 555 555 0123")).toBe("+15555550123");
|
2025-11-26 00:53:53 +01:00
|
|
|
});
|
2025-11-24 17:23:59 +01:00
|
|
|
|
2025-11-26 00:53:53 +01:00
|
|
|
it("adds plus when missing", () => {
|
|
|
|
|
expect(normalizeE164("1555123")).toBe("+1555123");
|
|
|
|
|
});
|
2025-11-24 17:23:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("toWhatsappJid", () => {
|
2025-11-26 00:53:53 +01:00
|
|
|
it("converts E164 to jid", () => {
|
2025-12-07 04:42:58 +00:00
|
|
|
expect(toWhatsappJid("+1 555 555 0123")).toBe("15555550123@s.whatsapp.net");
|
2025-11-26 00:53:53 +01:00
|
|
|
});
|
2025-12-23 03:05:59 +01:00
|
|
|
|
|
|
|
|
it("keeps group JIDs intact", () => {
|
2026-01-14 14:31:43 +00:00
|
|
|
expect(toWhatsappJid("123456789-987654321@g.us")).toBe("123456789-987654321@g.us");
|
2025-12-23 03:05:59 +01:00
|
|
|
});
|
2025-11-24 17:23:59 +01:00
|
|
|
});
|
|
|
|
|
|
2026-01-13 06:16:43 +00:00
|
|
|
describe("assertWebChannel", () => {
|
|
|
|
|
it("accepts valid channels", () => {
|
|
|
|
|
expect(() => assertWebChannel("web")).not.toThrow();
|
2025-11-26 00:53:53 +01:00
|
|
|
});
|
2025-11-24 17:23:59 +01:00
|
|
|
|
2026-01-13 06:16:43 +00:00
|
|
|
it("throws on invalid channel", () => {
|
|
|
|
|
expect(() => assertWebChannel("invalid" as string)).toThrow();
|
2025-11-26 00:53:53 +01:00
|
|
|
});
|
2025-11-24 17:23:59 +01:00
|
|
|
});
|