template_0205

This commit is contained in:
Sofio
2026-02-05 13:16:05 +08:00
commit d93e4d9c9f
197 changed files with 52810 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
import { ApiErrorResponse } from "apisauce"
import { getGeneralApiProblem } from "./apiProblem"
test("handles connection errors", () => {
expect(getGeneralApiProblem({ problem: "CONNECTION_ERROR" } as ApiErrorResponse<null>)).toEqual({
kind: "cannot-connect",
temporary: true,
})
})
test("handles network errors", () => {
expect(getGeneralApiProblem({ problem: "NETWORK_ERROR" } as ApiErrorResponse<null>)).toEqual({
kind: "cannot-connect",
temporary: true,
})
})
test("handles timeouts", () => {
expect(getGeneralApiProblem({ problem: "TIMEOUT_ERROR" } as ApiErrorResponse<null>)).toEqual({
kind: "timeout",
temporary: true,
})
})
test("handles server errors", () => {
expect(getGeneralApiProblem({ problem: "SERVER_ERROR" } as ApiErrorResponse<null>)).toEqual({
kind: "server",
})
})
test("handles unknown errors", () => {
expect(getGeneralApiProblem({ problem: "UNKNOWN_ERROR" } as ApiErrorResponse<null>)).toEqual({
kind: "unknown",
temporary: true,
})
})
test("handles unauthorized errors", () => {
expect(
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 401 } as ApiErrorResponse<null>),
).toEqual({
kind: "unauthorized",
})
})
test("handles forbidden errors", () => {
expect(
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 403 } as ApiErrorResponse<null>),
).toEqual({
kind: "forbidden",
})
})
test("handles not-found errors", () => {
expect(
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 404 } as ApiErrorResponse<null>),
).toEqual({
kind: "not-found",
})
})
test("handles other client errors", () => {
expect(
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 418 } as ApiErrorResponse<null>),
).toEqual({
kind: "rejected",
})
})
test("handles cancellation errors", () => {
expect(getGeneralApiProblem({ problem: "CANCEL_ERROR" } as ApiErrorResponse<null>)).toBeNull()
})