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:
@@ -1,22 +1,113 @@
|
||||
meta {
|
||||
name: Get Media Item,
|
||||
type: http,
|
||||
name: Get Media Item
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: "/api/media-items/{{ _.mediaItemId }}"
|
||||
headers: {
|
||||
Authorization: "Bearer {{ _.token }}",
|
||||
Content-Type: "application/json"
|
||||
url: {{base_url}}/api/media-items/{{mediaItemId}}
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
headers {
|
||||
Content-Type: application/json
|
||||
}
|
||||
|
||||
tests {
|
||||
test_get_media_item_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 (!data || typeof data !== "object") {
|
||||
throw new Error("Expected response body to be an object");
|
||||
}
|
||||
|
||||
// Check for required fields in media item
|
||||
if (!data.id) {
|
||||
throw new Error("Media item missing required field: id");
|
||||
}
|
||||
|
||||
if (!data.title) {
|
||||
throw new Error("Media item missing required field: title");
|
||||
}
|
||||
|
||||
if (!data.library_id) {
|
||||
throw new Error("Media item missing required field: library_id");
|
||||
}
|
||||
|
||||
if (!data.media_type) {
|
||||
throw new Error("Media item missing required field: media_type");
|
||||
}
|
||||
|
||||
// Validate data types
|
||||
if (typeof data.id !== "string") {
|
||||
throw new Error("Media item id must be a string");
|
||||
}
|
||||
|
||||
if (typeof data.title !== "string") {
|
||||
throw new Error("Media item title must be a string");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
tests: {
|
||||
test_get_media_item_success: {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
vars:pre-request {
|
||||
mediaItemId: "9932c704-i29b-81d4-e716-446655440004"
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
## Get Media Item
|
||||
|
||||
Retrieves detailed information about a specific media item.
|
||||
|
||||
**Method:** GET
|
||||
|
||||
**Endpoint:** /api/media-items/{id}
|
||||
|
||||
**Authentication:** Required (Bearer token)
|
||||
|
||||
**Path Parameters:**
|
||||
- `id` (string, required): Media item UUID
|
||||
|
||||
**Response:** Media item object
|
||||
- `id` (string): Media item UUID
|
||||
- `title` (string): Media item title
|
||||
- `description` (string, optional): Media description
|
||||
- `library_id` (string): Library UUID
|
||||
- `media_type` (string): Type of media (e.g., "ebook", "audiobook")
|
||||
- `file_path` (string): Path to media file
|
||||
- `file_size` (number, optional): File size in bytes
|
||||
- `metadata` (object, optional): Additional media metadata
|
||||
- `author` (string, optional): Author name (for books)
|
||||
- `isbn` (string, optional): ISBN number
|
||||
- `duration` (number, optional): Duration in seconds (for audiobooks)
|
||||
- `created_at` (string): Creation timestamp
|
||||
- `updated_at` (string): Last update timestamp
|
||||
|
||||
**Status Codes:**
|
||||
- 200: Success
|
||||
- 401: Unauthorized
|
||||
- 403: Forbidden (access denied)
|
||||
- 404: Media item not found
|
||||
- 500: Internal server error
|
||||
}
|
||||
Reference in New Issue
Block a user