Files
bookhoard/bruno/saved-filters/Update Saved Filter.yml
T
john-okeefe 2022595fd4 test(api): add Bruno API collection for saved filters
Add comprehensive Bruno OpenCollection YAML files for testing
the saved filters API with 9 request files and scenarios.

Main CRUD Requests (4 files):
1. List Saved Filters.yml
   - GET /api/saved-filters?resource_type=media-items
   - Documents resource_type parameter requirement
   - Example responses with JSONB filters

2. Create Saved Filter.yml
   - POST /api/saved-filters
   - Complete request body documentation
   - All filter field examples (genre, author, sort, year, etc.)
   - Validation rules (max 100 chars, uniqueness)

3. Update Saved Filter.yml
   - PUT /api/saved-filters/{filter_id}
   - Immutability notes (resource_type can't change)
   - Duplicate name validation
   - Updated timestamp behavior

4. Delete Saved Filter.yml
   - DELETE /api/saved-filters/{filter_id}
   - 204 No Content response
   - Security considerations

Scenario Test Files (5 files):

1. Duplicate Name Validation.yml
   - Tests 409 Conflict on duplicate names
   - Per-user + per-resource-type uniqueness
   - Example bash test script

2. User Isolation - Cross-User Access.yml
   - Tests users can't access each other's filters
   - Security: 404 instead of 403 (prevents enumeration)
   - Complete multi-user test scenario
   - Database-level isolation documentation

3. Multiple Resource Types.yml
   - Tests generic design with different resource types
   - Same name allowed for different types (media-items, collections, devices)
   - Examples for each resource type
   - Extensibility benefits explained

4. Complete CRUD Workflow.yml
   - End-to-end lifecycle test (6.5K file)
   - Shell script with all steps: Create → Read → Update → Delete → Verify
   - Success criteria checklist
   - Copy-paste ready test script

5. Filter Validation - Edge Cases.yml
   - 12 different validation test cases
   - Empty names, missing fields, invalid UUIDs
   - Unicode support (emoji, CJK characters)
   - Malformed JSON handling
   - Special characters and XSS attempts

Documentation Features:
- {{base_url}} variable substitution
- auth: inherit for authentication
- Comprehensive docs: sections with examples
- Shell commands ready to copy-paste
- Expected status codes and responses
- Error handling examples
- Security best practices

Total: 9 YAML files covering all CRUD operations and edge cases

Usage:
- Import into Bruno/Postman for API testing
- Use for manual testing during development
- Reference for API contract validation
- Example curl commands for documentation

Part of: Saved Filters Implementation (Phase 5: Testing & Documentation)
Related: #saved-filters-feature
2026-03-21 00:16:29 -04:00

118 lines
3.2 KiB
YAML

info:
name: Update Saved Filter
type: http
seq: 3
http:
method: PUT
url: '{{base_url}}/api/saved-filters/{{filter_id}}'
auth: inherit
body:
type: json
jsonBody: "{\n \"name\": \"Updated Sci-Fi Books\",\n \"resource_type\"\
: \"media-items\",\n \"filters\": {\n \"genre_filter\": \"Science Fiction\
\ Fantasy\",\n \"sort\": \"author ASC\",\n \"year_min\": \"2000\"\
\n }\n }"
docs: |-
## Update Saved Filter
Updates an existing saved filter's name and/or filter criteria.
**Method:** PUT
**Endpoint:** /api/saved-filters/{filter_id}
**Authentication:** Required (Bearer token)
**Path Parameters:**
- `filter_id` (string, required): UUID of the filter to update
- Must be a valid UUID
- Must belong to the authenticated user
**Request Body:**
```json
{
"name": "Updated Sci-Fi Books",
"resource_type": "media-items",
"filters": {
"genre_filter": "Science Fiction Fantasy",
"sort": "author ASC",
"year_min": "2000",
"year_max": "2024"
}
}
```
**Required Fields:**
- `name` (string, required): New filter name
- Must be unique per user + resource type (excluding current filter)
- Maximum 100 characters
- `resource_type` (string, required): Resource type (must match existing)
- Cannot change resource type after creation
- `filters` (object, required): Updated filter criteria
- Replaces existing filters entirely
**Response:**
```json
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Updated Sci-Fi Books",
"resource_type": "media-items",
"filters": {
"genre_filter": "Science Fiction Fantasy",
"sort": "author ASC",
"year_min": "2000",
"year_max": "2024"
},
"created_at": "2024-03-20T12:00:00Z",
"updated_at": "2024-03-20T15:30:00Z"
}
```
**Status Codes:**
- 200: Success - Filter updated successfully
- 400: Bad Request - Invalid request body or filter ID
- 401: Unauthorized - Invalid or missing authentication token
- 404: Not Found - Filter doesn't exist or doesn't belong to user
- 409: Conflict - New name conflicts with existing filter
**Error Response Examples:**
Filter not found:
```json
{
"error": "filter not found or access denied"
}
```
Duplicate name:
```json
{
"error": "filter with name 'Updated Sci-Fi Books' already exists for this resource type"
}
```
**Example Usage:**
```bash
curl -X PUT \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Sci-Fi Books",
"resource_type": "media-items",
"filters": {
"genre_filter": "Science Fiction Fantasy",
"sort": "author ASC",
"year_min": "2000"
}
}' \
"{{base_url}}/api/saved-filters/{{filter_id}}"
```
**Important Notes:**
- You can only update filters that belong to you
- The `updated_at` timestamp is automatically updated
- Cannot change the resource_type (it's immutable)
- New name must not conflict with other filters you own for the same resource type
- All filter fields are replaced entirely (partial updates not supported)