























@@ -412,13 +412,15 @@ describe("startTelegramWebhook", () => {
412412initSpy.mockClear();
413413createTelegramBotSpy.mockClear();
414414const runtimeLog = vi.fn();
415+const setStatus = vi.fn();
415416const cfg = { bindings: [] };
416417await withStartedWebhook(
417418{
418419secret: TELEGRAM_SECRET,
419420accountId: "opie",
420421config: cfg,
421422runtime: { log: runtimeLog, error: vi.fn(), exit: vi.fn() },
423+ setStatus,
422424},
423425async ({ port }) => {
424426expect(createTelegramBotSpy).toHaveBeenCalledWith(
@@ -438,20 +440,36 @@ describe("startTelegramWebhook", () => {
438440expect(runtimeLog).toHaveBeenCalledWith(
439441expect.stringContaining("webhook advertised to telegram on http://"),
440442);
443+expect(setStatus).toHaveBeenNthCalledWith(1, {
444+mode: "webhook",
445+connected: false,
446+lastConnectedAt: null,
447+lastEventAt: null,
448+lastTransportActivityAt: null,
449+});
450+expect(setStatus).toHaveBeenNthCalledWith(2, {
451+mode: "webhook",
452+connected: true,
453+lastConnectedAt: expect.any(Number),
454+lastEventAt: expect.any(Number),
455+lastError: null,
456+});
441457},
442458);
443459});
444460445461it("keeps local listener alive and retries when setWebhook has a recoverable startup failure", async () => {
446462const runtimeLog = vi.fn();
447463const runtimeError = vi.fn();
464+const setStatus = vi.fn();
448465setWebhookSpy.mockRejectedValueOnce(new TypeError("fetch failed")).mockResolvedValueOnce(true);
449466450467await withStartedWebhook(
451468{
452469secret: TELEGRAM_SECRET,
453470path: TELEGRAM_WEBHOOK_PATH,
454471runtime: { log: runtimeLog, error: runtimeError, exit: vi.fn() },
472+ setStatus,
455473webhookRegistrationRetryPolicy: {
456474initialMs: 0,
457475maxMs: 0,
@@ -471,6 +489,18 @@ describe("startTelegramWebhook", () => {
471489expect(runtimeLog).toHaveBeenCalledWith(
472490expect.stringContaining("webhook advertised to telegram on http://"),
473491);
492+expect(setStatus).toHaveBeenCalledWith({
493+mode: "webhook",
494+connected: false,
495+lastError: "fetch failed",
496+});
497+expect(setStatus).toHaveBeenCalledWith(
498+expect.objectContaining({
499+mode: "webhook",
500+connected: true,
501+lastError: null,
502+}),
503+);
474504},
475505);
476506});
@@ -532,13 +562,15 @@ describe("startTelegramWebhook", () => {
532562it("invokes webhook handler on matching path", async () => {
533563handleUpdateSpy.mockClear();
534564createTelegramBotSpy.mockClear();
565+const setStatus = vi.fn();
535566const cfg = { bindings: [] };
536567await withStartedWebhook(
537568{
538569secret: TELEGRAM_SECRET,
539570accountId: "opie",
540571config: cfg,
541572path: TELEGRAM_WEBHOOK_PATH,
573+ setStatus,
542574},
543575async ({ port }) => {
544576expect(createTelegramBotSpy).toHaveBeenCalledWith(
@@ -555,6 +587,13 @@ describe("startTelegramWebhook", () => {
555587});
556588expect(response.status).toBe(200);
557589await vi.waitFor(() => expect(handleUpdateSpy).toHaveBeenCalledWith(JSON.parse(payload)));
590+expect(setStatus).toHaveBeenCalledWith(
591+expect.objectContaining({
592+mode: "webhook",
593+connected: true,
594+lastError: null,
595+}),
596+);
558597},
559598);
560599});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。