refactor: standardize Bruno API requests with bruToJsonV2 format
- Convert all JSON tests to JavaScript functions for bruToJsonV2 compatibility
- Update authentication to use 'inherit' instead of manual headers
- Fix hardcoded URLs to use {{base_url}} variables
- Standardize variable syntax from {{ _.var }} to {{var}}
- Add comprehensive API documentation to all requests
- Update environment variables with missing required fields
- Apply consistent structure: meta, http method, headers, tests, vars, settings, docs
- Enhanced validation with proper error handling and field checks
This commit is contained in:
@@ -5,18 +5,79 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: "/api/libraries/types"
|
||||
headers: {
|
||||
Authorization: "Bearer {{ _.token }}",
|
||||
Content-Type: "application/json"
|
||||
url: {{base_url}}/api/libraries/types
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
headers {
|
||||
Content-Type: application/json
|
||||
}
|
||||
|
||||
tests {
|
||||
test_get_library_types_success(status, headers, body) {
|
||||
if (status !== 200) {
|
||||
throw new Error("Expected status 200, got " + status);
|
||||
}
|
||||
|
||||
const contentType = headers["content-type"];
|
||||
if (!contentType || !contentType.includes("application/json")) {
|
||||
throw new Error("Expected content-type to contain application/json, got " + contentType);
|
||||
}
|
||||
|
||||
// Verify response body is valid JSON and has expected structure
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(body);
|
||||
} catch (e) {
|
||||
throw new Error("Response body is not valid JSON");
|
||||
}
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error("Expected response body to be an array");
|
||||
}
|
||||
|
||||
// Validate each library type
|
||||
data.forEach((type, index) => {
|
||||
if (!type || typeof type !== "object") {
|
||||
throw new Error("Library type at index " + index + " is not an object");
|
||||
}
|
||||
|
||||
if (!type.id) {
|
||||
throw new Error("Library type at index " + index + " missing required field: id");
|
||||
}
|
||||
|
||||
if (!type.name) {
|
||||
throw new Error("Library type at index " + index + " missing required field: name");
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
tests: {
|
||||
test_library_types_success: {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
## Get Library Types
|
||||
|
||||
Retrieves all available library types that can be used when creating libraries.
|
||||
|
||||
**Method:** GET
|
||||
|
||||
**Endpoint:** /api/libraries/types
|
||||
|
||||
**Authentication:** Required (Bearer token)
|
||||
|
||||
**Response:** Array of library type objects
|
||||
- `id` (string): Type identifier (e.g., "ebooks", "audiobooks", "videos", "other")
|
||||
- `name` (string): Display name for the type (e.g., "Ebooks", "Audiobooks", "Videos", "Other")
|
||||
- `description` (string, optional): Description of what this type is used for
|
||||
|
||||
**Status Codes:**
|
||||
- 200: Success
|
||||
- 401: Unauthorized
|
||||
- 500: Internal server error
|
||||
}
|
||||
Reference in New Issue
Block a user