4.2 KiB
4.2 KiB
Test Ingredient Composition Endpoints
1. Add Compositions (Bulk)
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:
{
"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
PUT http://localhost:4000/api/v1/ingredients/compositions/{composition_id}
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZW1haWwiOiJhZG1pbkBnb2t1bmEuaWQiLCJyb2xlIjoiYWRtaW4iLCJvcmdhbml6YXRpb25faWQiOiIwMzIwNWQ4Zi0yYzA2LTQ1MTMtYTk1Mi0yMWQxMTA5Zjc4ZmYiLCJpc3MiOiJhcHNrZWwtcG9zIiwic3ViIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZXhwIjoxNzg1OTE0ODQ4LCJuYmYiOjE3NzcyNzQ4NDgsImlhdCI6MTc3NzI3NDg0OH0.prO4mU1zjVUZLgi5c8hj10A6ODETCMjnEP8wUQikZ30
Content-Type: application/json
{
"quantity": 3.5
}
Expected Response:
{
"success": true,
"data": {
"id": "composition_id",
"child_ingredient_id": "...",
"quantity": 3.5,
"child_ingredient": {...},
"parent_ingredient": {
"id": "...",
"cost": 18.75,
"compositions": [...]
}
}
}
3. Delete Composition
DELETE http://localhost:4000/api/v1/ingredients/compositions/{composition_id}
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZW1haWwiOiJhZG1pbkBnb2t1bmEuaWQiLCJyb2xlIjoiYWRtaW4iLCJvcmdhbml6YXRpb25faWQiOiIwMzIwNWQ4Zi0yYzA2LTQ1MTMtYTk1Mi0yMWQxMTA5Zjc4ZmYiLCJpc3MiOiJhcHNrZWwtcG9zIiwic3ViIjoiNmM2ZDI0MjAtNzA0MS00ZWE5LWE3MjYtYTM0MDAxNGJiMjRkIiwiZXhwIjoxNzg1OTE0ODQ4LCJuYmYiOjE3NzcyNzQ4NDgsImlhdCI6MTc3NzI3NDg0OH0.prO4mU1zjVUZLgi5c8hj10A6ODETCMjnEP8wUQikZ30
Expected Response:
{
"success": true,
"data": {
"id": "parent_ingredient_id",
"name": "Semi-Finished Product",
"cost": 12.25,
"compositions": [
// remaining compositions after deletion
]
}
}
Steps to Test:
- Get a semi-finished ingredient ID (or create one first)
- Get child ingredient IDs (raw ingredients to add as compositions)
- Add compositions using the bulk endpoint
- Copy composition ID from the response
- Update or Delete using that composition ID
cURL Commands:
Delete Composition:
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_1andCHILD_INGREDIENT_UUID_2with actual child ingredient UUIDs - Parent ingredient must have
is_semi_finished: true - All responses now include the updated parent ingredient with recalculated cost