Skip to content

Commit 30c17fe

Browse files
committed
test: guard whatsapp send api mock calls
1 parent 3a4c97c commit 30c17fe

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

extensions/whatsapp/src/inbound/send-api.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ describe("createWebSendApi", () => {
5252
}
5353

5454
function requireSendContent(callIndex = 0): Record<string, unknown> {
55-
return requireRecord(sendMessage.mock.calls[callIndex]?.[1], "sent message content");
55+
return requireRecord(sendMessage.mock.calls.at(callIndex)?.[1], "sent message content");
5656
}
5757

5858
function requireSendOptions(callIndex = 0): Record<string, unknown> {
59-
return requireRecord(sendMessage.mock.calls[callIndex]?.[2], "sent message options");
59+
return requireRecord(sendMessage.mock.calls.at(callIndex)?.[2], "sent message options");
6060
}
6161

6262
function expectSendContentFields(callIndex: number, fields: Record<string, unknown>) {
@@ -73,7 +73,7 @@ describe("createWebSendApi", () => {
7373
it("uses sendOptions fileName for outbound documents", async () => {
7474
const payload = Buffer.from("pdf");
7575
await api.sendMessage("+1555", "doc", payload, "application/pdf", { fileName: "invoice.pdf" });
76-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
76+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
7777
expectSendContentFields(0, {
7878
document: payload,
7979
fileName: "invoice.pdf",
@@ -90,7 +90,7 @@ describe("createWebSendApi", () => {
9090
it("falls back to default document filename when fileName is absent", async () => {
9191
const payload = Buffer.from("pdf");
9292
await api.sendMessage("+1555", "doc", payload, "application/pdf");
93-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
93+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
9494
expectSendContentFields(0, {
9595
document: payload,
9696
fileName: "file",
@@ -143,7 +143,7 @@ describe("createWebSendApi", () => {
143143
it("supports image media with caption", async () => {
144144
const payload = Buffer.from("img");
145145
await api.sendMessage("+1555", "cap", payload, "image/jpeg");
146-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
146+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
147147
expectSendContentFields(0, {
148148
image: payload,
149149
caption: "cap",
@@ -166,7 +166,7 @@ describe("createWebSendApi", () => {
166166

167167
await api.sendMessage("[email protected]", "cap @15551234567", payload, "image/jpeg");
168168

169-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
169+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
170170
expectSendContentFields(0, {
171171
image: payload,
172172
caption: "cap @15551234567",
@@ -178,7 +178,7 @@ describe("createWebSendApi", () => {
178178
it("supports audio as push-to-talk voice note", async () => {
179179
const payload = Buffer.from("aud");
180180
await api.sendMessage("+1555", "", payload, "audio/ogg", { accountId: "alt" });
181-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
181+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
182182
expectSendContentFields(0, {
183183
audio: payload,
184184
ptt: true,
@@ -197,7 +197,7 @@ describe("createWebSendApi", () => {
197197
.mockResolvedValueOnce({ key: { id: "voice-1" } })
198198
.mockResolvedValueOnce({ key: { id: "voice-text-1" } });
199199
const res = await api.sendMessage("+1555", "voice text", payload, "audio/ogg");
200-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
200+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
201201
expectSendContentFields(0, {
202202
audio: payload,
203203
ptt: true,
@@ -220,7 +220,7 @@ describe("createWebSendApi", () => {
220220
it("supports video media and gifPlayback option", async () => {
221221
const payload = Buffer.from("vid");
222222
await api.sendMessage("+1555", "cap", payload, "video/mp4", { gifPlayback: true });
223-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
223+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
224224
expectSendContentFields(0, {
225225
video: payload,
226226
caption: "cap",
@@ -241,7 +241,7 @@ describe("createWebSendApi", () => {
241241
options: ["a", "b"],
242242
maxSelections: 2,
243243
});
244-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
244+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
245245
expect(requireSendContent().poll).toEqual({
246246
name: "Q?",
247247
values: ["a", "b"],
@@ -257,7 +257,7 @@ describe("createWebSendApi", () => {
257257

258258
it("sends reactions with participant JID normalization", async () => {
259259
const res = await api.sendReaction("+1555", "msg-2", "👍", false, "+1999");
260-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
260+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
261261
const react = requireRecord(requireSendContent().react, "reaction content");
262262
expect(react.text).toBe("👍");
263263
expectRecordFields(requireRecord(react.key, "reaction key"), {
@@ -288,7 +288,7 @@ describe("createWebSendApi", () => {
288288

289289
it("keeps direct-chat reactions without a participant key", async () => {
290290
await api.sendReaction("+1555", "msg-2", "👍", false);
291-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
291+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
292292
const react = requireRecord(requireSendContent().react, "reaction content");
293293
expect(react.text).toBe("👍");
294294
expectRecordFields(requireRecord(react.key, "reaction key"), {
@@ -301,7 +301,7 @@ describe("createWebSendApi", () => {
301301

302302
it("preserves LID participants in reaction keys", async () => {
303303
await api.sendReaction("[email protected]", "msg-2", "👍", false, "123@lid");
304-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
304+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
305305
const react = requireRecord(requireSendContent().react, "reaction content");
306306
expect(react.text).toBe("👍");
307307
expectRecordFields(requireRecord(react.key, "reaction key"), {
@@ -334,7 +334,7 @@ describe("createWebSendApi", () => {
334334

335335
await api.sendMessage("123", "hello", mediaBuffer, undefined);
336336

337-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
337+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
338338
expectSendContentFields(0, {
339339
document: mediaBuffer,
340340
mimetype: "application/octet-stream",
@@ -358,8 +358,8 @@ describe("createWebSendApi", () => {
358358
},
359359
});
360360

361-
expect(sendMessage.mock.calls[0]?.[0]).toBe("[email protected]");
362-
expect(sendMessage.mock.calls[0]?.[1]).toEqual({ text: "hello" });
361+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("[email protected]");
362+
expect(sendMessage.mock.calls.at(0)?.[1]).toEqual({ text: "hello" });
363363
const quoted = requireRecord(requireSendOptions().quoted, "quoted message");
364364
expectRecordFields(requireRecord(quoted.key, "quoted key"), {
365365
remoteJid: "277038292303944@lid",
@@ -420,8 +420,8 @@ describe("createWebSendApi LID resolution (issue #67378)", () => {
420420
authDir,
421421
});
422422
await api.sendPoll("+15555550000", { question: "Q?", options: ["a", "b"] });
423-
expect(sendMessage.mock.calls[0]?.[0]).toBe("987654@lid");
424-
const payload = requireRecord(sendMessage.mock.calls[0]?.[1], "send poll payload");
423+
expect(sendMessage.mock.calls.at(0)?.[0]).toBe("987654@lid");
424+
const payload = requireRecord(sendMessage.mock.calls.at(0)?.[1], "send poll payload");
425425
expect("poll" in payload).toBe(true);
426426
});
427427

0 commit comments

Comments
 (0)