scoootscooob 16505718e8
refactor: move WhatsApp channel implementation to extensions/ (#45725)
* refactor: move WhatsApp channel from src/web/ to extensions/whatsapp/

Move all WhatsApp implementation code (77 source/test files + 9 channel
plugin files) from src/web/ and src/channels/plugins/*/whatsapp* to
extensions/whatsapp/src/.

- Leave thin re-export shims at all original locations so cross-cutting
  imports continue to resolve
- Update plugin-sdk/whatsapp.ts to only re-export generic framework
  utilities; channel-specific functions imported locally by the extension
- Update vi.mock paths in 15 cross-cutting test files
- Rename outbound.ts -> send.ts to match extension naming conventions
  and avoid false positive in cfg-threading guard test
- Widen tsconfig.plugin-sdk.dts.json rootDir to support shim->extension
  cross-directory references

Part of the core-channels-to-extensions migration (PR 6/10).

* style: format WhatsApp extension files

* fix: correct stale import paths in WhatsApp extension tests

Fix vi.importActual, test mock, and hardcoded source paths that weren't
updated during the file move:
- media.test.ts: vi.importActual path
- onboarding.test.ts: vi.importActual path
- test-helpers.ts: test/mocks/baileys.js path
- monitor-inbox.test-harness.ts: incomplete media/store mock
- login.test.ts: hardcoded source file path
- message-action-runner.media.test.ts: vi.mock/importActual path
2026-03-14 02:44:55 -07:00

57 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { formatGroupMembers, noteGroupMember } from "./group-members.js";
describe("noteGroupMember", () => {
it("normalizes member phone numbers before storing", () => {
const groupMemberNames = new Map<string, Map<string, string>>();
noteGroupMember(groupMemberNames, "g1", "+1 (555) 123-4567", "Alice");
expect(groupMemberNames.get("g1")?.get("+15551234567")).toBe("Alice");
});
it("ignores incomplete member values", () => {
const groupMemberNames = new Map<string, Map<string, string>>();
noteGroupMember(groupMemberNames, "g1", undefined, "Alice");
noteGroupMember(groupMemberNames, "g1", "+15551234567", undefined);
expect(groupMemberNames.get("g1")).toBeUndefined();
});
});
describe("formatGroupMembers", () => {
it("deduplicates participants and appends named roster members", () => {
const roster = new Map<string, string>([
["+16660000000", "Bob"],
["+17770000000", "Carol"],
]);
const formatted = formatGroupMembers({
participants: ["+1 (555) 000-0000", "+15550000000", "+16660000000"],
roster,
});
expect(formatted).toBe("+15550000000, Bob (+16660000000), Carol (+17770000000)");
});
it("falls back to sender when no participants or roster are available", () => {
const formatted = formatGroupMembers({
participants: [],
roster: undefined,
fallbackE164: "+1 (555) 222-3333",
});
expect(formatted).toBe("+15552223333");
});
it("returns undefined when no members can be resolved", () => {
expect(
formatGroupMembers({
participants: [],
roster: undefined,
}),
).toBeUndefined();
});
});