apskel-pos-backend/test_composition_endpoints.md
2026-04-27 21:17:12 +07:00

124 lines
4.2 KiB
Markdown

# Test Ingredient Composition Endpoints
## 1. Add Compositions (Bulk)
```bash
POST http://localhost:4000/api/v1/ingredients/{ingredient_id}/compositions
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZW1haWwiOiJhZG1pbkBnb2t1bmEuaWQiLCJyb2xlIjoiYWRtaW4iLCJvcmdhbml6YXRpb25faWQiOiIwMzIwNWQ4Zi0yYzA2LTQ1MTMtYTk1Mi0yMWQxMTA5Zjc4ZmYiLCJpc3MiOiJhcHNrZWwtcG9zIiwic3ViIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZXhwIjoxNzg1OTE0ODQ4LCJuYmYiOjE3NzcyNzQ4NDgsImlhdCI6MTc3NzI3NDg0OH0.prO4mU1zjVUZLgi5c8hj10A6ODETCMjnEP8wUQikZ30
Content-Type: application/json
{
"compositions": [
{
"child_ingredient_id": "CHILD_INGREDIENT_UUID_1",
"quantity": 2.5
},
{
"child_ingredient_id": "CHILD_INGREDIENT_UUID_2",
"quantity": 1.0
}
]
}
```
**Expected Response:**
```json
{
"success": true,
"data": {
"parent_ingredient": {
"id": "uuid",
"name": "Semi-Finished Product",
"cost": 15.50,
"compositions": [...]
},
"compositions": [
{
"id": "COMPOSITION_ID_1",
"child_ingredient_id": "...",
"quantity": 2.5,
"child_ingredient": {...},
"parent_ingredient": {...}
}
]
}
}
```
## 2. Update Composition
```bash
PUT http://localhost:4000/api/v1/ingredients/compositions/{composition_id}
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZW1haWwiOiJhZG1pbkBnb2t1bmEuaWQiLCJyb2xlIjoiYWRtaW4iLCJvcmdhbml6YXRpb25faWQiOiIwMzIwNWQ4Zi0yYzA2LTQ1MTMtYTk1Mi0yMWQxMTA5Zjc4ZmYiLCJpc3MiOiJhcHNrZWwtcG9zIiwic3ViIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZXhwIjoxNzg1OTE0ODQ4LCJuYmYiOjE3NzcyNzQ4NDgsImlhdCI6MTc3NzI3NDg0OH0.prO4mU1zjVUZLgi5c8hj10A6ODETCMjnEP8wUQikZ30
Content-Type: application/json
{
"quantity": 3.5
}
```
**Expected Response:**
```json
{
"success": true,
"data": {
"id": "composition_id",
"child_ingredient_id": "...",
"quantity": 3.5,
"child_ingredient": {...},
"parent_ingredient": {
"id": "...",
"cost": 18.75,
"compositions": [...]
}
}
}
```
## 3. Delete Composition
```bash
DELETE http://localhost:4000/api/v1/ingredients/compositions/{composition_id}
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZW1haWwiOiJhZG1pbkBnb2t1bmEuaWQiLCJyb2xlIjoiYWRtaW4iLCJvcmdhbml6YXRpb25faWQiOiIwMzIwNWQ4Zi0yYzA2LTQ1MTMtYTk1Mi0yMWQxMTA5Zjc4ZmYiLCJpc3MiOiJhcHNrZWwtcG9zIiwic3ViIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZXhwIjoxNzg1OTE0ODQ4LCJuYmYiOjE3NzcyNzQ4NDgsImlhdCI6MTc3NzI3NDg0OH0.prO4mU1zjVUZLgi5c8hj10A6ODETCMjnEP8wUQikZ30
```
**Expected Response:**
```json
{
"success": true,
"data": {
"id": "parent_ingredient_id",
"name": "Semi-Finished Product",
"cost": 12.25,
"compositions": [
// remaining compositions after deletion
]
}
}
```
## Steps to Test:
1. **Get a semi-finished ingredient ID** (or create one first)
2. **Get child ingredient IDs** (raw ingredients to add as compositions)
3. **Add compositions** using the bulk endpoint
4. **Copy composition ID** from the response
5. **Update or Delete** using that composition ID
## cURL Commands:
### Delete Composition:
```bash
curl --request DELETE \
--url 'http://localhost:4000/api/v1/ingredients/compositions/YOUR_COMPOSITION_ID_HERE' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZW1haWwiOiJhZG1pbkBnb2t1bmEuaWQiLCJyb2xlIjoiYWRtaW4iLCJvcmdhbml6YXRpb25faWQiOiIwMzIwNWQ4Zi0yYzA2LTQ1MTMtYTk1Mi0yMWQxMTA5Zjc4ZmYiLCJpc3MiOiJhcHNrZWwtcG9zIiwic3ViIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZXhwIjoxNzg1OTE0ODQ4LCJuYmYiOjE3NzcyNzQ4NDgsImlhdCI6MTc3NzI3NDg0OH0.prO4mU1zjVUZLgi5c8hj10A6ODETCMjnEP8wUQikZ30'
```
## Notes:
- Replace `{ingredient_id}` with actual parent ingredient UUID
- Replace `{composition_id}` with actual composition UUID
- Replace `CHILD_INGREDIENT_UUID_1` and `CHILD_INGREDIENT_UUID_2` with actual child ingredient UUIDs
- Parent ingredient must have `is_semi_finished: true`
- All responses now include the updated parent ingredient with recalculated cost