Update configuration key naming convention to use snake_case consistently. Applies changes recursively across all subdirectories.
120 lines
2.8 KiB
Plaintext
120 lines
2.8 KiB
Plaintext
meta {
|
|
name: Test Collection Rules
|
|
type: http
|
|
seq: 1
|
|
}
|
|
|
|
post {
|
|
url: {{base_url}}/api/collections/test-rules
|
|
body: json
|
|
auth: inherit
|
|
}
|
|
|
|
headers {
|
|
Content-Type: application/json
|
|
Authorization: Bearer {{authToken}}
|
|
}
|
|
|
|
body:json {
|
|
{
|
|
"rules": [
|
|
{
|
|
"field": "genre",
|
|
"operator": "equals",
|
|
"value": "Science Fiction"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
script:post-response {
|
|
function onResponse(res) {
|
|
if (res.getStatus() === 200) {
|
|
tests['Rules test successful'] = true;
|
|
const body = res.getBody();
|
|
tests['Has matches array'] = Array.isArray(body.matches);
|
|
tests['Has total count'] = body.total !== undefined;
|
|
} else {
|
|
tests['Rules test failed'] = false;
|
|
}
|
|
}
|
|
onResponse(res);
|
|
}
|
|
|
|
settings {
|
|
encodeUrl: true
|
|
timeout: 0
|
|
}
|
|
|
|
docs {
|
|
## Test Collection Rules
|
|
|
|
Tests collection rules against the library to see which books match, without creating a collection. Useful for previewing what books would be included in a collection with specific rules.
|
|
|
|
**Method:** POST
|
|
|
|
**Endpoint:** /api/collections/test-rules
|
|
|
|
**Authentication:** Bearer token
|
|
|
|
**Request Body:**
|
|
- `rules` (array): Array of rule objects to test
|
|
- `field` (string): Field to test (genre, author, copyright_year, tags, etc.)
|
|
- `operator` (string): Comparison operator
|
|
- `equals`: Exact match
|
|
- `contains`: Contains substring (for text fields)
|
|
- `greater_than`: Greater than (for numeric fields)
|
|
- `less_than`: Less than (for numeric fields)
|
|
- `not_equals`: Not equal to
|
|
- `starts_with`: Starts with
|
|
- `ends_with`: Ends with
|
|
- `is_empty`: Field is empty or null
|
|
- `is_not_empty`: Field is not empty and not null
|
|
- `value` (string): Value to compare against (not required for is_empty/is_not_empty)
|
|
|
|
**Response:**
|
|
- `matches` (array): Array of matching books
|
|
- `id` (string): Book UUID
|
|
- `title` (string): Book title
|
|
- `author` (string): Book author
|
|
- `genre` (string): Book genre
|
|
- Additional book metadata
|
|
- `total` (number): Total number of matching books
|
|
|
|
**Status Codes:**
|
|
- 200: Success - returns matching books
|
|
- 400: Invalid request (empty rules array, invalid field/operator)
|
|
- 401: Unauthorized
|
|
- 500: Internal server error
|
|
|
|
**Example Request:**
|
|
```json
|
|
{
|
|
"rules": [
|
|
{
|
|
"field": "genre",
|
|
"operator": "equals",
|
|
"value": "Science Fiction"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
**Example Response:**
|
|
```json
|
|
{
|
|
"matches": [
|
|
{
|
|
"id": "book-uuid-1",
|
|
"title": "Foundation",
|
|
"author": "Isaac Asimov",
|
|
"genre": "Science Fiction"
|
|
}
|
|
],
|
|
"total": 1
|
|
}
|
|
```
|
|
|
|
**Note:** This endpoint is useful for validating collection rules before creating a collection, or for dynamically querying books based on criteria.
|
|
}
|