-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94c042f
commit 202c0ca
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { expect, test } from "vitest"; | ||
import { | ||
isProblemDetails, | ||
ProblemDetails | ||
} from "../../../src/models/problemDetails"; | ||
|
||
test("should return true when value is a ProblemDetails object", () => { | ||
const value: ProblemDetails = { | ||
title: "Internal Server Error", | ||
status: 500, | ||
detail: "An unexpected error occurred.", | ||
instance: "/api/users", | ||
errors: ["500", "Internal Server Error"] | ||
}; | ||
const result = isProblemDetails(value); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
test("should return false when value is not an object", () => { | ||
const value = "Invalid input"; | ||
const result = isProblemDetails(value); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
test("should return false when value is null", () => { | ||
const value = null; | ||
const result = isProblemDetails(value); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
test("should return false when status is not a number", () => { | ||
const value = { | ||
title: "Bad Request", | ||
status: "400", | ||
detail: "Invalid request.", | ||
instance: "/api/users", | ||
errors: ["400", "Bad Request"] | ||
}; | ||
const result = isProblemDetails(value); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
test("should return true when errors is an array", () => { | ||
const value: ProblemDetails = { | ||
title: "Not Found", | ||
status: 404, | ||
detail: "Resource not found.", | ||
instance: "/api/users", | ||
errors: ["", ""] | ||
}; | ||
const result = isProblemDetails(value); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
test("should return false when errors is not an array", () => { | ||
const value = { | ||
title: "Unauthorized", | ||
status: 401, | ||
detail: "Access denied.", | ||
instance: "/api/users", | ||
errors: "401" | ||
}; | ||
const result = isProblemDetails(value); | ||
|
||
expect(result).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters