File size: 1,923 Bytes
fc93158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { describe, it, expect } from "vitest";
import { isNonRecoverableSlackAuthError } from "./provider.js";

describe("isNonRecoverableSlackAuthError", () => {
  it.each([
    "An API error occurred: account_inactive",
    "An API error occurred: invalid_auth",
    "An API error occurred: token_revoked",
    "An API error occurred: token_expired",
    "An API error occurred: not_authed",
    "An API error occurred: org_login_required",
    "An API error occurred: team_access_not_granted",
    "An API error occurred: missing_scope",
    "An API error occurred: cannot_find_service",
    "An API error occurred: invalid_token",
  ])("returns true for non-recoverable error: %s", (msg) => {
    expect(isNonRecoverableSlackAuthError(new Error(msg))).toBe(true);
  });

  it("returns true when error is a plain string", () => {
    expect(isNonRecoverableSlackAuthError("account_inactive")).toBe(true);
  });

  it("matches case-insensitively", () => {
    expect(isNonRecoverableSlackAuthError(new Error("ACCOUNT_INACTIVE"))).toBe(true);
    expect(isNonRecoverableSlackAuthError(new Error("Invalid_Auth"))).toBe(true);
  });

  it.each([
    "Connection timed out",
    "ECONNRESET",
    "Network request failed",
    "socket hang up",
    "ETIMEDOUT",
    "rate_limited",
  ])("returns false for recoverable/transient error: %s", (msg) => {
    expect(isNonRecoverableSlackAuthError(new Error(msg))).toBe(false);
  });

  it("returns false for non-error values", () => {
    expect(isNonRecoverableSlackAuthError(null)).toBe(false);
    expect(isNonRecoverableSlackAuthError(undefined)).toBe(false);
    expect(isNonRecoverableSlackAuthError(42)).toBe(false);
    expect(isNonRecoverableSlackAuthError({})).toBe(false);
  });

  it("returns false for empty string", () => {
    expect(isNonRecoverableSlackAuthError("")).toBe(false);
    expect(isNonRecoverableSlackAuthError(new Error(""))).toBe(false);
  });
});