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:
2026-01-28 20:13:56 -05:00
parent 935b867219
commit 8db5939892
27 changed files with 1269 additions and 182 deletions
+101 -15
View File
@@ -1,25 +1,111 @@
meta {
name: Create Media Rating,
type: http,
name: Create Media Rating
type: http
seq: 1
}
post {
url: "/api/media-items/{{ _.mediaItemId }}/rating"
headers: {
Authorization: "Bearer {{ _.token }}",
Content-Type: "application/json"
}
body: {
rating: {{ _.rating }}
url: {{base_url}}/api/media-items/{{mediaItemId}}/rating
auth: inherit
body: json
}
headers {
Content-Type: application/json
}
body:json {
{
"rating": 8
}
}
tests: {
test_create_rating_success: {
status: 201,
headers: {
"content-type": "application/json"
tests {
test_create_rating_success(status, headers, body) {
if (status !== 201) {
throw new Error("Expected status 201, 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 rating response
if (!data.id) {
throw new Error("Rating response missing required field: id");
}
if (!data.media_item_id) {
throw new Error("Rating response missing required field: media_item_id");
}
if (typeof data.rating !== "number" || data.rating < 1 || data.rating > 10) {
throw new Error("Invalid rating value: " + data.rating + " (must be 1-10)");
}
return true;
}
}
}
vars:pre-request {
mediaItemId: "9932c704-i29b-81d4-e716-446655440004"
}
settings {
encodeUrl: true
timeout: 0
}
docs {
## Create Media Rating
Creates or updates the authenticated user's rating for a specific media item.
**Method:** POST
**Endpoint:** /api/media-items/{id}/rating
**Authentication:** Required (Bearer token)
**Path Parameters:**
- `id` (string, required): Media item UUID
**Request Body:**
- `rating` (number, required): Rating value (1-10, where odd numbers = half-stars)
- 1,3,5,7,9 = 0.5,1.5,2.5,3.5,4.5 stars (half-star precision)
- 2,4,6,8,10 = 1,2,3,4,5 stars (full stars)
**Example Request:**
- `"rating": 7` = 3.5 stars (frontend display)
- `"rating": 8` = 4.0 stars (frontend display)
**Response:** Rating object
- `id` (string): Rating UUID
- `media_item_id` (string): Media item UUID
- `user_id` (string): User UUID
- `rating` (number): Rating value (1-10)
- `created_at` (string): Creation timestamp
- `updated_at` (string): Last update timestamp
**Status Codes:**
- 201: Rating created successfully
- 200: Rating updated successfully (if rating already existed)
- 400: Invalid rating value (must be 1-10)
- 401: Unauthorized
- 403: Forbidden (rating access denied)
- 404: Media item not found
- 500: Internal server error
}
+104 -13
View File
@@ -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
}
+94 -13
View File
@@ -1,22 +1,103 @@
meta {
name: List Media Items,
type: http,
name: List Media Items
type: http
seq: 1
}
get {
url: "/api/media-items?library_id={{ _.libraryId }}&limit=20&offset=0"
headers: {
Authorization: "Bearer {{ _.token }}",
Content-Type: "application/json"
url: {{base_url}}/api/media-items?library_id={{libraryId}}&limit=20&offset=0
auth: inherit
}
headers {
Content-Type: application/json
}
tests {
test_list_media_items_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 media item in the array
data.forEach((item, index) => {
if (!item || typeof item !== "object") {
throw new Error("Media item at index " + index + " is not an object");
}
if (!item.id) {
throw new Error("Media item at index " + index + " missing required field: id");
}
if (!item.title) {
throw new Error("Media item at index " + index + " missing required field: title");
}
if (!item.library_id) {
throw new Error("Media item at index " + index + " missing required field: library_id");
}
});
return true;
}
}
tests: {
test_list_media_items_success: {
status: 200,
headers: {
"content-type": "application/json"
}
}
vars:pre-request {
libraryId: "8821b703-h29b-71d4-d716-446655440003"
}
settings {
encodeUrl: true
timeout: 0
}
docs {
## List Media Items
Retrieves a paginated list of media items from a specific library.
**Method:** GET
**Endpoint:** /api/media-items
**Authentication:** Required (Bearer token)
**Query Parameters:**
- `library_id` (string, required): Library UUID to filter items
- `limit` (number, optional): Number of results per page (default: 20, max: 100)
- `offset` (number, optional): Pagination offset (default: 0)
**Response:** Array of media item objects
- `id` (string): Media item UUID
- `title` (string): Media item title
- `library_id` (string): Library UUID
- `media_type` (string): Type of media (e.g., "ebook", "audiobook")
- `file_path` (string): Path to media file
- `created_at` (string): Creation timestamp
- `updated_at` (string): Last update timestamp
**Status Codes:**
- 200: Success
- 400: Invalid query parameters
- 401: Unauthorized
- 403: Forbidden (library access denied)
- 404: Library not found
- 500: Internal server error
}