@@ -6,6 +6,21 @@ import {
|
6 | 6 | } from "./account-throttler.js"; |
7 | 7 | |
8 | 8 | type TelegramPreviousCall = Parameters<ReturnType<typeof createTelegramAccountThrottler>>[0]; |
| 9 | +type TelegramTransform = ReturnType<typeof createTelegramAccountThrottler>; |
| 10 | + |
| 11 | +function callLooseSendMessage( |
| 12 | +throttler: TelegramTransform, |
| 13 | +prev: TelegramPreviousCall, |
| 14 | +payload: Record<string, unknown>, |
| 15 | +) { |
| 16 | +const loose = throttler as ( |
| 17 | +prev: TelegramPreviousCall, |
| 18 | +method: "sendMessage", |
| 19 | +payload: unknown, |
| 20 | +signal: undefined, |
| 21 | +) => ReturnType<TelegramTransform>; |
| 22 | +return loose(prev, "sendMessage", payload, undefined); |
| 23 | +} |
9 | 24 | |
10 | 25 | function deferred<T>() { |
11 | 26 | let resolve: (value: T) => void; |
@@ -169,26 +184,23 @@ describe("getOrCreateAccountThrottler", () => {
|
169 | 184 | return { ok: true, result: request.text ?? "" }; |
170 | 185 | }) as unknown as TelegramPreviousCall; |
171 | 186 | |
172 | | -const first = throttler( |
173 | | -prev, |
174 | | -"sendMessage", |
175 | | -{ chat_id: "-100123", message_thread_id: "+10", text: "first" }, |
176 | | -undefined, |
177 | | -); |
| 187 | +const first = callLooseSendMessage(throttler, prev, { |
| 188 | +chat_id: "-100123", |
| 189 | +message_thread_id: "+10", |
| 190 | +text: "first", |
| 191 | +}); |
178 | 192 | await vi.waitFor(() => expect(entered).toEqual(["+10:first"])); |
179 | 193 | |
180 | | -const sameTopic = throttler( |
181 | | -prev, |
182 | | -"sendMessage", |
183 | | -{ chat_id: "-100123", message_thread_id: "+10", text: "second" }, |
184 | | -undefined, |
185 | | -); |
186 | | -const otherTopic = throttler( |
187 | | -prev, |
188 | | -"sendMessage", |
189 | | -{ chat_id: "-100123", message_thread_id: "0x20", text: "hex" }, |
190 | | -undefined, |
191 | | -); |
| 194 | +const sameTopic = callLooseSendMessage(throttler, prev, { |
| 195 | +chat_id: "-100123", |
| 196 | +message_thread_id: "+10", |
| 197 | +text: "second", |
| 198 | +}); |
| 199 | +const otherTopic = callLooseSendMessage(throttler, prev, { |
| 200 | +chat_id: "-100123", |
| 201 | +message_thread_id: "0x20", |
| 202 | +text: "hex", |
| 203 | +}); |
192 | 204 | |
193 | 205 | firstGate.resolve(); |
194 | 206 | await vi.waitFor(() => expect(entered.length).toBeGreaterThanOrEqual(2)); |
|