refactor: centralize WhatsApp target normalization
This commit is contained in:
@@ -6,11 +6,9 @@ import {
|
||||
assertProvider,
|
||||
CONFIG_DIR,
|
||||
ensureDir,
|
||||
isWhatsAppGroupJid,
|
||||
jidToE164,
|
||||
normalizeE164,
|
||||
normalizePath,
|
||||
normalizeWhatsAppTarget,
|
||||
resolveJidToE164,
|
||||
resolveUserPath,
|
||||
sleep,
|
||||
@@ -86,55 +84,6 @@ describe("normalizeE164 & toWhatsappJid", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeWhatsAppTarget", () => {
|
||||
it("preserves group JIDs", () => {
|
||||
expect(normalizeWhatsAppTarget("120363401234567890@g.us")).toBe(
|
||||
"120363401234567890@g.us",
|
||||
);
|
||||
expect(normalizeWhatsAppTarget("123456789-987654321@g.us")).toBe(
|
||||
"123456789-987654321@g.us",
|
||||
);
|
||||
expect(normalizeWhatsAppTarget("whatsapp:120363401234567890@g.us")).toBe(
|
||||
"120363401234567890@g.us",
|
||||
);
|
||||
expect(
|
||||
normalizeWhatsAppTarget("whatsapp:group:120363401234567890@g.us"),
|
||||
).toBe("120363401234567890@g.us");
|
||||
expect(normalizeWhatsAppTarget("group:123456789-987654321@g.us")).toBe(
|
||||
"123456789-987654321@g.us",
|
||||
);
|
||||
expect(
|
||||
normalizeWhatsAppTarget(" WhatsApp:Group:123456789-987654321@G.US "),
|
||||
).toBe("123456789-987654321@g.us");
|
||||
});
|
||||
|
||||
it("normalizes direct JIDs to E.164", () => {
|
||||
expect(normalizeWhatsAppTarget("1555123@s.whatsapp.net")).toBe("+1555123");
|
||||
});
|
||||
|
||||
it("rejects invalid targets", () => {
|
||||
expect(normalizeWhatsAppTarget("wat")).toBe("");
|
||||
expect(normalizeWhatsAppTarget("whatsapp:")).toBe("");
|
||||
expect(normalizeWhatsAppTarget("@g.us")).toBe("");
|
||||
expect(normalizeWhatsAppTarget("whatsapp:group:@g.us")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("isWhatsAppGroupJid", () => {
|
||||
it("detects group JIDs with or without prefixes", () => {
|
||||
expect(isWhatsAppGroupJid("120363401234567890@g.us")).toBe(true);
|
||||
expect(isWhatsAppGroupJid("123456789-987654321@g.us")).toBe(true);
|
||||
expect(isWhatsAppGroupJid("whatsapp:120363401234567890@g.us")).toBe(true);
|
||||
expect(isWhatsAppGroupJid("whatsapp:group:120363401234567890@g.us")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isWhatsAppGroupJid("x@g.us")).toBe(false);
|
||||
expect(isWhatsAppGroupJid("@g.us")).toBe(false);
|
||||
expect(isWhatsAppGroupJid("120@g.usx")).toBe(false);
|
||||
expect(isWhatsAppGroupJid("+1555123")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("jidToE164", () => {
|
||||
it("maps @lid using reverse mapping file", () => {
|
||||
const mappingPath = path.join(
|
||||
|
||||
Reference in New Issue
Block a user