mirror of
https://github.com/coder/coder.git
synced 2026-10-24 01:26:25 +08:00
39 lines
990 B
TypeScript
39 lines
990 B
TypeScript
import { isApiError, mapApiErrorToFieldErrors } from "./errors"
|
|
|
|
describe("isApiError", () => {
|
|
it("returns true when the object is an API Error", () => {
|
|
expect(
|
|
isApiError({
|
|
isAxiosError: true,
|
|
response: {
|
|
data: {
|
|
message: "Invalid entry",
|
|
errors: [{ detail: "Username is already in use", field: "username" }],
|
|
},
|
|
},
|
|
}),
|
|
).toBe(true)
|
|
})
|
|
|
|
it("returns false when the object is Error", () => {
|
|
expect(isApiError(new Error())).toBe(false)
|
|
})
|
|
|
|
it("returns false when the object is undefined", () => {
|
|
expect(isApiError(undefined)).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe("mapApiErrorToFieldErrors", () => {
|
|
it("returns correct field errors", () => {
|
|
expect(
|
|
mapApiErrorToFieldErrors({
|
|
message: "Invalid entry",
|
|
errors: [{ detail: "Username is already in use", field: "username" }],
|
|
}),
|
|
).toEqual({
|
|
username: "Username is already in use",
|
|
})
|
|
})
|
|
})
|