test(dashboard): implement Phase 5 Bruno API tests for Carousel-style dashboard

Update and create Bruno API tests to reflect new unified collections architecture:

Updated Tests:
1. get-dashboard-sections.yml
   - Updated response structure documentation
   - Changed from type field to is_system boolean
   - Changed from id to media_item_id in items
   - Added priority field documentation
   - Updated example response to show unified collections structure
   - Added test for sections array in response

2. update-preferences.yml
   - Changed HTTP method from POST to PUT (matching handler implementation)
   - Updated request body field names:
     * hidden_sections → hidden_collections
     * section_order → collection_order
   - Updated documentation with new field names
   - Updated example request with valid system collection names

New Tests:
3. restore-system-collection.yml
   - Tests POST /api/dashboard/restore-system-collection endpoint
   - Validates collection_name against allowed system collections
   - Tests success response with message
   - Documents valid collection names:
     * continue-reading
     * recently-added
     * recently-read
     * not-started

Test Coverage:
- GET /api/dashboard/sections: Returns all dashboard sections
- PUT /api/dashboard/preferences: Updates user preferences
- POST /api/dashboard/restore-system-collection: Resets system collection

All tests follow Bruno YAML format with proper authentication via auth: inherit.
This commit is contained in:
2026-02-19 21:02:47 -05:00
parent 804dc6d069
commit 190914c004
3 changed files with 140 additions and 60 deletions
+58 -37
View File
@@ -4,49 +4,70 @@ info:
seq: 1
http:
method: GET
url: '{{base_url}}/api/dashboard/sections'
url: '{{base_url}}/api/dashboard/sections?library_id={{library_id}}'
auth: inherit
body:
type: none
runtime:
scripts:
- type: tests
code: "test(\"status must be 200 with auth\", function() {\n expect(res.status).to.eql(200);"
code: "test(\"status must be 200 with auth\", function() {\n expect(res.status).to.eql(200);\n\
});\n\ntest(\"response contains sections array\", function() {\n expect(res.body.sections).to.exist;\n\
expect(res.body.sections).to.be.an('array');\n });"
docs: |-
Get all dashboard sections for a specific library.
**Endpoint**: GET /api/dashboard/sections
**Auth**: Required (Bearer token via auth: inherit)
## Query Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| library_id | string | Yes | Library UUID |
## Response
Returns array of sections including:
- Smart sections (continue-reading, in-progress, recently-added, etc.)
- User collections marked with show_on_dashboard: true
## Section Types
| Type | Description |
|------|-------------|
| smart | Auto-generated sections based on user activity |
| collection | User-created collections with dashboard enabled |
## Example Response
```json
{
"sections": [
{
"id": "continue-reading",
"type": "smart",
"title": "Continue Reading",
"icon": "📖",
"items": [...],
"view_all_url": "/section/continue-reading"
**Endpoint**: GET /api/dashboard/sections
**Auth**: Required (Bearer token via auth: inherit)
## Query Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| library_id | string | Yes | Library UUID |
| limit | int | No | Items per section (default: 20, max: 100) |
## Response
Returns array of sections including:
- System collections (continue-reading, recently-added, recently-read, not-started)
- User collections marked with show_on_dashboard: true
## Section Structure
Each section has:
- `id`: Collection name (string)
- `is_system`: Boolean indicating if this is a system collection
- `title`: Display title
- `description`: Collection description
- `icon`: Emoji icon
- `items`: Array of BookInfo objects
- `view_all_url`: URL to view all items (system collections only)
- `priority`: Display order (lower numbers first)
## Example Response
```json
{
"sections": [
{
"id": "continue-reading",
"is_system": true,
"title": "Continue Reading",
"description": "Books you're currently reading (0 < progress < 1)",
"icon": "📖",
"items": [
{
"media_item_id": "uuid",
"title": "Book Title",
"author": "Author Name",
"cover_image_path": "/path/to/cover.jpg"
}
],
"view_all_url": "/section/continue-reading",
"priority": 1
}
]
}
```
@@ -0,0 +1,47 @@
info:
name: Restore System Collection
type: http
seq: 3
http:
method: POST
url: '{{base_url}}/api/dashboard/restore-system-collection'
auth: inherit
body:
type: json
jsonBody: "{\n \"collection_name\": \"continue-reading\"\n}"
runtime:
scripts:
- type: tests
code: "test(\"status must be 200 with valid collection\", function() {\n expect(res.status).to.eql(200);\n\
});\n\ntest(\"response has success message\", function() {\n expect(res.body.message).to.exist;\n\
});"
docs: |-
Restore a system collection to its default state.
**Endpoint**: POST /api/dashboard/restore-system-collection
**Auth**: Required (Bearer token)
## Request Body
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| collection_name | string | Yes | Name of system collection to restore |
Valid collection names:
- `continue-reading`: Books you're currently reading (0 < progress < 1)
- `recently-added`: Newly added items to this library
- `recently-read`: Books you've finished (progress >= 1)
- `not-started`: Books you haven't read yet (progress = 0 or no record)
## Example Request
```json
{
"collection_name": "continue-reading"
}
```
## Response
Returns success message on restore.
+35 -23
View File
@@ -3,34 +3,46 @@ info:
type: http
seq: 2
http:
method: POST
method: PUT
url: '{{base_url}}/api/dashboard/preferences'
auth: inherit
body:
type: json
jsonBody: "{\n \"library_id\": \"{{library_id}}\",\n \"hidden_collections\"\
: [\"not-started\"],\n \"collection_order\": [\"recently-added\", \"continue-reading\"\
, \"recently-read\"],\n \"items_per_section\": 20\n}"
runtime:
scripts:
- type: tests
code: "test(\"status must be 200 with valid request\", function() {\n expect(res.status).to.eql(200);"
code: "test(\"status must be 200 with valid request\", function() {\n expect(res.status).to.eql(200);\n\
});"
docs: |-
Update dashboard preferences for the authenticated user.
**Endpoint**: POST /api/dashboard/preferences
**Auth**: Required (Bearer token)
## Request Body
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| library_id | string | Yes | Library UUID |
| hidden_sections | array | No | Section IDs to hide |
| section_order | array | No | Section IDs in custom order |
| items_per_section | int | No | Items to show per section (10-50) |
## Example Request
```json
{
"library_id": "cc23c3a7-f8fb-451a-a78d-2a16df1b725a",
"hidden_sections": ["recently-added"],
"section_order": ["continue-reading", "in-progress"],
"items_per_section": 25
**Endpoint**: PUT /api/dashboard/preferences
**Auth**: Required (Bearer token)
## Request Body
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| library_id | string | Yes | Library UUID |
| hidden_collections | array | No | Collection names to hide from dashboard |
| collection_order | array | No | Collection names in custom display order |
| items_per_section | int | No | Items to show per section (default: 20) |
## Example Request
```json
{
"library_id": "cc23c3a7-f8fb-451a-a78d-2a16df1b725a",
"hidden_collections": ["not-started"],
"collection_order": ["recently-added", "continue-reading", "recently-read"],
"items_per_section": 20
}
```
## Response
Returns updated preferences object on success.