|
2 | 2 | import { createServer, type Server } from "node:http"; |
3 | 3 | import type { AddressInfo } from "node:net"; |
4 | 4 | import { WebClient } from "@slack/web-api"; |
5 | | -import { afterEach, describe, expect, it } from "vitest"; |
| 5 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
6 | 6 | import { |
7 | 7 | createSlackLookupClient, |
8 | 8 | createSlackReadClient, |
| 9 | + createSlackStartupAuthClient, |
9 | 10 | createSlackWebClient, |
10 | 11 | getSlackListenerUploadCompletionClient, |
11 | 12 | } from "./client.js"; |
@@ -187,6 +188,42 @@ afterEach(() => { |
187 | 188 | }); |
188 | 189 |
|
189 | 190 | describe("Slack Web API routing", () => { |
| 191 | + it("retries two transient startup auth failures", async () => { |
| 192 | + const fetchMock = vi |
| 193 | + .fn() |
| 194 | + .mockRejectedValueOnce(new Error("request timed out")) |
| 195 | + .mockRejectedValueOnce(new Error("connection reset")) |
| 196 | + .mockResolvedValueOnce( |
| 197 | + new Response(JSON.stringify({ ok: true, team_id: "TMOCK", user_id: "UMOCK" }), { |
| 198 | + status: 200, |
| 199 | + }), |
| 200 | + ); |
| 201 | + const client = createSlackStartupAuthClient("startup-fixture", { |
| 202 | + fetch: fetchMock as never, |
| 203 | + }); |
| 204 | + |
| 205 | + await expect(client.auth.test()).resolves.toMatchObject({ |
| 206 | + ok: true, |
| 207 | + team_id: "TMOCK", |
| 208 | + user_id: "UMOCK", |
| 209 | + }); |
| 210 | + expect(fetchMock).toHaveBeenCalledTimes(3); |
| 211 | + }); |
| 212 | + |
| 213 | + it("does not retry a permanent startup auth error", async () => { |
| 214 | + const fetchMock = vi.fn().mockResolvedValue( |
| 215 | + new Response(JSON.stringify({ ok: false, error: "invalid_auth" }), { |
| 216 | + status: 200, |
| 217 | + }), |
| 218 | + ); |
| 219 | + const client = createSlackStartupAuthClient("invalid-fixture", { |
| 220 | + fetch: fetchMock as never, |
| 221 | + }); |
| 222 | + |
| 223 | + await expect(client.auth.test()).rejects.toThrow("invalid_auth"); |
| 224 | + expect(fetchMock).toHaveBeenCalledTimes(1); |
| 225 | + }); |
| 226 | + |
190 | 227 | it("aborts a stalled-header lookup after one request", async () => { |
191 | 228 | for (const key of TEST_ENV_KEYS) { |
192 | 229 | delete process.env[key]; |
|
0 commit comments