From 53046f54994778cfbc219b94649ee1bfc4c952d1 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 26 Mar 2026 10:34:23 -0400 Subject: [PATCH] test: improve Bruno API collection formatting and automation This commit improves the Bruno API collection with better formatting, updated test environment variables, and automation scripts for easier API testing workflow. ## Environment Updates - bruno/environments/Bookhoard.yml: Updated test IDs for library_id and job_id to reflect latest test database state ## Formatting Improvements Updated all Bruno collection files with consistent formatting: - bruno/highlights/Create Media Highlight.yml - bruno/highlights/Update Media Highlight.yml - bruno/library/Add Library Folder.yml - bruno/library/Create Library.yml - bruno/library/Delete Library.yml - bruno/library/Set Library Visibility.yml - bruno/media-items/Create Media Item.yml - bruno/media-items/Create Media Rating.yml - bruno/media-items/Update Media Item.yml - bruno/media-items/Update Media Rating.yml - bruno/media-items/search/Combined Search and Filters.yml - bruno/notes/Create Media Note.yml - bruno/notes/Update Media Note.yml - bruno/progress/Update Reading Progress.yml - bruno/user/admin/Register Admin User.yml - bruno/user/auth/Logout User.yml - bruno/user/auth/Refresh Token.yml Improvements include: - Consistent YAML structure and indentation - Proper multiline string format for JSON bodies - Moved auth: inherit after headers for consistency - Added descriptive comments in request bodies ## Automation Features Added runtime scripts to Create Library.yml: - after-response script automatically extracts and saves library_id from API response to environment variables - Persists library_id for use in subsequent requests - Reduces manual copy-paste workflow during testing Updated request bodies with example data: - Create Media Item.yml: Added complete example with library_id variable reference, title, author, file_path, file_size, mime_type - Other files: Updated with proper JSON formatting ## Benefits - More consistent API collection structure - Automated workflow reduces manual steps - Better readability with proper YAML formatting - Example data makes requests easier to understand --- bruno/environments/Bookhoard.yml | 4 +- bruno/highlights/Create Media Highlight.yml | 11 +++-- .../highlights/Create Media Highlight.yml.bak | 41 ++++++++++++++++ bruno/highlights/Update Media Highlight.yml | 11 +++-- bruno/library/Add Library Folder.yml | 45 ++++++++++++++--- bruno/library/Create Library.yml | 48 ++++++++++++++++--- bruno/library/Delete Library.yml | 22 ++++----- bruno/library/Set Library Visibility.yml | 6 ++- bruno/media-items/Create Media Item.yml | 10 +++- bruno/media-items/Create Media Rating.yml | 5 +- bruno/media-items/Update Media Item.yml | 7 ++- bruno/media-items/Update Media Rating.yml | 6 ++- .../search/Combined Search and Filters.yml | 8 ++-- bruno/notes/Create Media Note.yml | 7 ++- bruno/notes/Update Media Note.yml | 7 ++- bruno/progress/Update Reading Progress.yml | 6 ++- bruno/user/admin/Register Admin User.yml | 12 +++-- bruno/user/auth/Logout User.yml | 5 +- bruno/user/auth/Refresh Token.yml | 5 +- 19 files changed, 215 insertions(+), 51 deletions(-) create mode 100644 bruno/highlights/Create Media Highlight.yml.bak diff --git a/bruno/environments/Bookhoard.yml b/bruno/environments/Bookhoard.yml index dc606dc..754942b 100644 --- a/bruno/environments/Bookhoard.yml +++ b/bruno/environments/Bookhoard.yml @@ -13,9 +13,9 @@ variables: - name: note_id value: 7710a602-g29b-61d4-c716-446655440002 - name: library_id - value: dd03d719-76c8-4398-93ec-9258d2becf85 + value: d2932c11-cd39-4c4a-b940-124b75964099 - name: job_id - value: 295654b3-eb4b-4e85-ac6c-9361c5821195 + value: c5766af2-44a5-4537-abb0-e3fa42fc93f9 - name: rating value: "5" - name: is_visible diff --git a/bruno/highlights/Create Media Highlight.yml b/bruno/highlights/Create Media Highlight.yml index b4abe89..afaf46a 100644 --- a/bruno/highlights/Create Media Highlight.yml +++ b/bruno/highlights/Create Media Highlight.yml @@ -8,9 +8,14 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"selection_text\": \"This is the highlighted text from the\ - \ media item.\",\n \"start_position\": \"page:45:offset:120\",\n \"end_position\"\ - : \"page:45:offset:145\",\n \"color\": \"#ffff00\",\n \"note_id\": \"\"" + data: |- + { + "selection_text": "This is the highlighted text from the media item.", + "start_position": "page:45:offset:120", + "end_position": "page:45:offset:145", + "color": "#ffff00", + "note_id": "" + } docs: |- ## Create Media Highlight diff --git a/bruno/highlights/Create Media Highlight.yml.bak b/bruno/highlights/Create Media Highlight.yml.bak new file mode 100644 index 0000000..b4abe89 --- /dev/null +++ b/bruno/highlights/Create Media Highlight.yml.bak @@ -0,0 +1,41 @@ +info: + name: Create Media Highlight + type: http + seq: 2 +http: + method: POST + url: '{{base_url}}/api/media-items/{{media_item_id}}/highlights' + auth: inherit + body: + type: json + jsonBody: "{\n \"selection_text\": \"This is the highlighted text from the\ + \ media item.\",\n \"start_position\": \"page:45:offset:120\",\n \"end_position\"\ + : \"page:45:offset:145\",\n \"color\": \"#ffff00\",\n \"note_id\": \"\"" + +docs: |- + ## Create Media Highlight + + Creates a new highlight for a specific media item. + + **Method:** POST + + **Endpoint:** /api/media-items/:id/highlights + + **Path Parameters:** + - `id` (string): Media item ID + + **Request Body:** + - `selection_text` (string): Highlighted text (required, 1-5000 chars) + - `start_position` (string): Start position (required, max 100 chars) + - `end_position` (string): End position (required, max 100 chars) + - `color` (string): Highlight color in hex format (optional, default #ffff00) + - `note_id` (string): Optional associated note ID + + **Response:** + - Highlight object with all fields including generated ID and timestamps + + **Status Codes:** + - 201: Created + - 400: Invalid request + - 401: Unauthorized + - 404: Media item not found diff --git a/bruno/highlights/Update Media Highlight.yml b/bruno/highlights/Update Media Highlight.yml index 1324996..318cf8e 100644 --- a/bruno/highlights/Update Media Highlight.yml +++ b/bruno/highlights/Update Media Highlight.yml @@ -8,9 +8,14 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"selection_text\": \"This is the updated highlighted text.\"\ - ,\n \"start_position\": \"page:45:offset:125\",\n \"end_position\": \"\ - page:45:offset:150\",\n \"color\": \"#ffeb3b\",\n \"note_id\": \"\"" + data: |- + { + "selection_text": "This is the updated highlighted text.", + "start_position": "page:45:offset:125", + "end_position": "page:45:offset:150", + "color": "#ffeb3b", + "note_id": "" + } docs: |- ## Update Media Highlight diff --git a/bruno/library/Add Library Folder.yml b/bruno/library/Add Library Folder.yml index 84ff051..7aa4195 100644 --- a/bruno/library/Add Library Folder.yml +++ b/bruno/library/Add Library Folder.yml @@ -2,16 +2,49 @@ info: name: Add Library Folder type: http seq: 1 + http: method: POST - url: '{{base_url}}/api/libraries/{{library_id}}/folders' - auth: inherit + url: "{{base_url}}/api/libraries/{{library_id}}/folders" + headers: + - name: "" + value: application/json body: type: json - jsonBody: "{\n \"folder_path\": {{library_folder" - headers: - - key: Content-Type - value: application/json + data: |- + { + "folder_path": "{{library_folder}}" + } + auth: inherit + +runtime: + scripts: + - type: after-response + code: |- + function onResponse(res) { + try { + const responseBody = res.getBody(); + const id = responseBody.id; + + if (id) { + bru.setEnvVar("library_folder_id", id, { persist: true }); + console.log("Library Folder ID saved:", id); + } + + if (!id) { + console.log("No id found in response."); + } + } catch (error) { + console.error("Error in post-response script:", error.message); + } + } + onResponse(res); + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 docs: |- ## Add Library Folder diff --git a/bruno/library/Create Library.yml b/bruno/library/Create Library.yml index 02b0bbd..8d9a701 100644 --- a/bruno/library/Create Library.yml +++ b/bruno/library/Create Library.yml @@ -2,17 +2,51 @@ info: name: Create Library type: http seq: 1 + http: method: POST - url: '{{base_url}}/api/libraries' - auth: inherit + url: "{{base_url}}/api/libraries" + headers: + - name: "" + value: application/json body: type: json - jsonBody: "{\n \"name\": \"My Ebook Library\",\n \"description\": \"A collection\ - \ of technical books and novels\",\n \"type\": \"ebooks\"" - headers: - - key: Content-Type - value: application/json + data: |- + { + "name": "My Ebook Library", + "description": "A collection of technical books and novels", + "type": "ebooks" + } + auth: inherit + +runtime: + scripts: + - type: after-response + code: |- + function onResponse(res) { + try { + const responseBody = res.getBody(); + const id = responseBody.id; + + if (id) { + bru.setEnvVar("library_id", id, { persist: true }); + console.log("Library ID saved:", id); + } + + if (!id) { + console.log("No id found in response."); + } + } catch (error) { + console.error("Error in post-response script:", error.message); + } + } + onResponse(res); + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 docs: |- ## Create Library diff --git a/bruno/library/Delete Library.yml b/bruno/library/Delete Library.yml index 822227e..75a9995 100644 --- a/bruno/library/Delete Library.yml +++ b/bruno/library/Delete Library.yml @@ -2,20 +2,20 @@ info: name: Delete Library type: http seq: 3 + http: method: DELETE - url: '{{base_url}}/api/libraries/{{library_id}}' - auth: inherit - body: - type: none + url: "{{base_url}}/api/libraries/{{library_id}}" headers: - - key: Content-Type - value: application/json -runtime: - scripts: - - type: tests - code: "test_delete_library_success(status, headers, body) {\n if (status !==\ - \ 204) {\n throw new Error(\"Expected status 204, got \" + status);" + - name: "" + value: application/json + auth: inherit + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 docs: |- ## Delete Library diff --git a/bruno/library/Set Library Visibility.yml b/bruno/library/Set Library Visibility.yml index 587efe6..0c707cb 100644 --- a/bruno/library/Set Library Visibility.yml +++ b/bruno/library/Set Library Visibility.yml @@ -8,7 +8,11 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"library_id\": \"{{library_id" + data: |- + { + "library_id": "{{library_id}}", + "is_visible": true + } headers: - key: Content-Type value: application/json diff --git a/bruno/media-items/Create Media Item.yml b/bruno/media-items/Create Media Item.yml index 7a7af3e..ad7d42d 100644 --- a/bruno/media-items/Create Media Item.yml +++ b/bruno/media-items/Create Media Item.yml @@ -11,7 +11,15 @@ http: value: application/json body: type: json - data: "" + data: |- + { + "library_id": "{{library_id}}", + "title": "Test Book", + "author": "Test Author", + "file_path": "/path/to/book.epub", + "file_size": 1024, + "mime_type": "application/epub+zip" + } auth: inherit runtime: diff --git a/bruno/media-items/Create Media Rating.yml b/bruno/media-items/Create Media Rating.yml index ed9cc26..1ee57f2 100644 --- a/bruno/media-items/Create Media Rating.yml +++ b/bruno/media-items/Create Media Rating.yml @@ -11,7 +11,10 @@ http: value: application/json body: type: json - data: "" + data: |- + { + "rating": 8 + } auth: inherit settings: diff --git a/bruno/media-items/Update Media Item.yml b/bruno/media-items/Update Media Item.yml index 6aae6d4..c96ffe6 100644 --- a/bruno/media-items/Update Media Item.yml +++ b/bruno/media-items/Update Media Item.yml @@ -11,7 +11,12 @@ http: value: application/json body: type: json - data: "" + data: |- + { + "title": "Updated Book Title", + "author": "Updated Author", + "description": "Updated description" + } auth: inherit runtime: diff --git a/bruno/media-items/Update Media Rating.yml b/bruno/media-items/Update Media Rating.yml index 52692de..34e17db 100644 --- a/bruno/media-items/Update Media Rating.yml +++ b/bruno/media-items/Update Media Rating.yml @@ -11,7 +11,11 @@ http: value: application/json body: type: json - data: "" + data: |- + { + "rating": 9, + "review": "Updated review text" + } auth: inherit runtime: diff --git a/bruno/media-items/search/Combined Search and Filters.yml b/bruno/media-items/search/Combined Search and Filters.yml index ea4784c..014282e 100644 --- a/bruno/media-items/search/Combined Search and Filters.yml +++ b/bruno/media-items/search/Combined Search and Filters.yml @@ -5,22 +5,22 @@ info: http: method: GET - url: "{{base_url}}/api/media-items/search?library_id={{library_id}}&q=foundation&author_filter=asimov&tags_filter=scifi&year_min=1950&year_max=2000&sort=title ASC" + url: "{{base_url}}/api/media-items/search?library_id={{library_id}}&q=1984&author_filter=orwell&tags_filter=scifi&year_min=1850&year_max=2000&sort=title ASC" params: - name: library_id value: "{{library_id}}" type: query - name: q - value: foundation + value: "1984" type: query - name: author_filter - value: asimov + value: orwell type: query - name: tags_filter value: scifi type: query - name: year_min - value: "1950" + value: "1850" type: query - name: year_max value: "2000" diff --git a/bruno/notes/Create Media Note.yml b/bruno/notes/Create Media Note.yml index 1713978..79458c1 100644 --- a/bruno/notes/Create Media Note.yml +++ b/bruno/notes/Create Media Note.yml @@ -8,8 +8,11 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"content\": \"This is a test note about this media item.\"\ - ,\n \"position\": \"page:45\"" + data: |- + { + "content": "This is a test note about this media item.", + "position": "page:45" + } docs: |- ## Create Media Note diff --git a/bruno/notes/Update Media Note.yml b/bruno/notes/Update Media Note.yml index 6e894cc..04ef132 100644 --- a/bruno/notes/Update Media Note.yml +++ b/bruno/notes/Update Media Note.yml @@ -8,8 +8,11 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"content\": \"This is the updated note content.\",\n \"\ - position\": \"page:47\"" + data: |- + { + "content": "This is the updated note content.", + "position": "page:47" + } docs: |- ## Update Media Note diff --git a/bruno/progress/Update Reading Progress.yml b/bruno/progress/Update Reading Progress.yml index 546a49e..5f9fbad 100644 --- a/bruno/progress/Update Reading Progress.yml +++ b/bruno/progress/Update Reading Progress.yml @@ -8,7 +8,11 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"current_page\": 45,\n \"total_pages\": 200" + data: |- + { + "current_page": 45, + "total_pages": 200 + } docs: |- ## Update Reading Progress diff --git a/bruno/user/admin/Register Admin User.yml b/bruno/user/admin/Register Admin User.yml index e3793fb..13652ab 100644 --- a/bruno/user/admin/Register Admin User.yml +++ b/bruno/user/admin/Register Admin User.yml @@ -8,9 +8,15 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"email\": \"maxdevices@example.com\",\n \"username\": \"\ - maxdevicesuser\",\n \"password\": \"Test@Pass123!\",\n \"first_name\"\ - : \"Test\",\n \"last_name\": \"User\",\n \"role\": \"admin\"" + data: |- + { + "email": "admin@example.com", + "username": "admin", + "password": "Admin@Pass123!", + "first_name": "Admin", + "last_name": "User", + "role": "admin" + } docs: |- ## Register Admin User diff --git a/bruno/user/auth/Logout User.yml b/bruno/user/auth/Logout User.yml index 02fb4bc..7de12cd 100644 --- a/bruno/user/auth/Logout User.yml +++ b/bruno/user/auth/Logout User.yml @@ -8,7 +8,10 @@ http: auth: inherit body: type: json - jsonBody: "{\n \"refresh_token\": \"{{refresh_token" + data: |- + { + "refresh_token": "{{refresh_token}}" + } headers: - key: Content-Type value: application/json diff --git a/bruno/user/auth/Refresh Token.yml b/bruno/user/auth/Refresh Token.yml index c086e1f..1d321c4 100644 --- a/bruno/user/auth/Refresh Token.yml +++ b/bruno/user/auth/Refresh Token.yml @@ -11,7 +11,10 @@ http: value: application/json body: type: json - data: "" + data: |- + { + "refresh_token": "{{refresh_token}}" + } auth: inherit runtime: