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,26 +1,99 @@
|
||||
meta {
|
||||
name: Set Library Visibility,
|
||||
type: http,
|
||||
name: Set Library Visibility
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: "/api/libraries/visibility"
|
||||
headers: {
|
||||
Authorization: "Bearer {{ _.token }}",
|
||||
Content-Type: "application/json"
|
||||
}
|
||||
body: {
|
||||
library_id: "{{ _.libraryId }}",
|
||||
is_visible: {{ _.isVisible }}
|
||||
url: {{base_url}}/api/libraries/visibility
|
||||
auth: inherit
|
||||
body: json
|
||||
}
|
||||
|
||||
headers {
|
||||
Content-Type: application/json
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"library_id": "{{libraryId}}",
|
||||
"is_visible": {{isVisible}}
|
||||
}
|
||||
}
|
||||
|
||||
tests: {
|
||||
test_set_visibility_success: {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
tests {
|
||||
test_set_visibility_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 response
|
||||
if (!data.library_id) {
|
||||
throw new Error("Response missing required field: library_id");
|
||||
}
|
||||
|
||||
if (typeof data.is_visible !== "boolean") {
|
||||
throw new Error("Response missing required field: is_visible or not boolean");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
libraryId: "8821b703-h29b-71d4-d716-446655440003",
|
||||
isVisible: true
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
## Set Library Visibility
|
||||
|
||||
Updates the visibility status of a library for regular users.
|
||||
|
||||
**Method:** POST
|
||||
|
||||
**Endpoint:** /api/libraries/visibility
|
||||
|
||||
**Authentication:** Required (Bearer token, admin permissions)
|
||||
|
||||
**Request Body:**
|
||||
- `library_id` (string, required): Library UUID
|
||||
- `is_visible` (boolean, required): Visibility status
|
||||
- `true`: Library visible to all users
|
||||
- `false`: Library hidden from regular users
|
||||
|
||||
**Response:** Updated library visibility object
|
||||
- `library_id` (string): Library UUID
|
||||
- `is_visible` (boolean): Updated visibility status
|
||||
- `updated_at` (string): Update timestamp
|
||||
|
||||
**Status Codes:**
|
||||
- 200: Visibility updated successfully
|
||||
- 400: Invalid request data
|
||||
- 401: Unauthorized
|
||||
- 403: Forbidden (admin access required)
|
||||
- 404: Library not found
|
||||
- 500: Internal server error
|
||||
}
|
||||
Reference in New Issue
Block a user