From 53aecf7a8e20c8b86367895de1cb36d8fd246d51 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 19 Feb 2026 10:09:27 +0000 Subject: [PATCH] test(bluebubbles): merge typing start stop method checks --- extensions/bluebubbles/src/chat.test.ts | 72 ++++++++----------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/extensions/bluebubbles/src/chat.test.ts b/extensions/bluebubbles/src/chat.test.ts index 755407e629..f372ca4614 100644 --- a/extensions/bluebubbles/src/chat.test.ts +++ b/extensions/bluebubbles/src/chat.test.ts @@ -153,23 +153,6 @@ describe("chat", () => { ).rejects.toThrow("password is required"); }); - it("sends typing start with POST method", async () => { - mockFetch.mockResolvedValueOnce({ - ok: true, - text: () => Promise.resolve(""), - }); - - await sendBlueBubblesTyping("iMessage;-;+15551234567", true, { - serverUrl: "http://localhost:1234", - password: "test", - }); - - expect(mockFetch).toHaveBeenCalledWith( - expect.stringContaining("/api/v1/chat/iMessage%3B-%3B%2B15551234567/typing"), - expect.objectContaining({ method: "POST" }), - ); - }); - it("does not send typing when private API is disabled", async () => { vi.mocked(getCachedBlueBubblesPrivateApiStatus).mockReturnValueOnce(false); @@ -181,21 +164,35 @@ describe("chat", () => { expect(mockFetch).not.toHaveBeenCalled(); }); - it("sends typing stop with DELETE method", async () => { - mockFetch.mockResolvedValueOnce({ - ok: true, - text: () => Promise.resolve(""), - }); + it("uses POST for start and DELETE for stop", async () => { + mockFetch + .mockResolvedValueOnce({ + ok: true, + text: () => Promise.resolve(""), + }) + .mockResolvedValueOnce({ + ok: true, + text: () => Promise.resolve(""), + }); + await sendBlueBubblesTyping("iMessage;-;+15551234567", true, { + serverUrl: "http://localhost:1234", + password: "test", + }); await sendBlueBubblesTyping("iMessage;-;+15551234567", false, { serverUrl: "http://localhost:1234", password: "test", }); - expect(mockFetch).toHaveBeenCalledWith( - expect.stringContaining("/api/v1/chat/iMessage%3B-%3B%2B15551234567/typing"), - expect.objectContaining({ method: "DELETE" }), + expect(mockFetch).toHaveBeenCalledTimes(2); + expect(mockFetch.mock.calls[0][0]).toContain( + "/api/v1/chat/iMessage%3B-%3B%2B15551234567/typing", ); + expect(mockFetch.mock.calls[0][1].method).toBe("POST"); + expect(mockFetch.mock.calls[1][0]).toContain( + "/api/v1/chat/iMessage%3B-%3B%2B15551234567/typing", + ); + expect(mockFetch.mock.calls[1][1].method).toBe("DELETE"); }); it("includes password in URL query", async () => { @@ -279,31 +276,6 @@ describe("chat", () => { expect(calledUrl).toContain("typing-server:8888"); expect(calledUrl).toContain("password=typing-pass"); }); - - it("can start and stop typing in sequence", async () => { - mockFetch - .mockResolvedValueOnce({ - ok: true, - text: () => Promise.resolve(""), - }) - .mockResolvedValueOnce({ - ok: true, - text: () => Promise.resolve(""), - }); - - await sendBlueBubblesTyping("chat-123", true, { - serverUrl: "http://localhost:1234", - password: "test", - }); - await sendBlueBubblesTyping("chat-123", false, { - serverUrl: "http://localhost:1234", - password: "test", - }); - - expect(mockFetch).toHaveBeenCalledTimes(2); - expect(mockFetch.mock.calls[0][1].method).toBe("POST"); - expect(mockFetch.mock.calls[1][1].method).toBe("DELETE"); - }); }); describe("setGroupIconBlueBubbles", () => {