feat: 支持用户自定义食物
This commit is contained in:
53
test-custom-foods.sh
Normal file
53
test-custom-foods.sh
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 用户自定义食物功能测试脚本
|
||||
|
||||
echo "=== 用户自定义食物功能测试 ==="
|
||||
|
||||
# 设置基础URL和测试用户token
|
||||
BASE_URL="http://localhost:3000"
|
||||
# 请替换为实际的用户token
|
||||
ACCESS_TOKEN="your_access_token_here"
|
||||
|
||||
echo "1. 测试获取食物库列表(包含用户自定义食物)"
|
||||
curl -X GET "$BASE_URL/food-library" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json"
|
||||
|
||||
echo -e "\n\n2. 测试创建用户自定义食物"
|
||||
curl -X POST "$BASE_URL/food-library/custom" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "我的自制沙拉",
|
||||
"description": "自制蔬菜沙拉",
|
||||
"categoryKey": "dishes",
|
||||
"caloriesPer100g": 120,
|
||||
"proteinPer100g": 5.2,
|
||||
"carbohydratePer100g": 15.3,
|
||||
"fatPer100g": 8.1,
|
||||
"fiberPer100g": 3.2,
|
||||
"sugarPer100g": 2.5,
|
||||
"sodiumPer100g": 150
|
||||
}'
|
||||
|
||||
echo -e "\n\n3. 测试搜索食物(包含用户自定义食物)"
|
||||
curl -X GET "$BASE_URL/food-library/search?keyword=沙拉" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json"
|
||||
|
||||
echo -e "\n\n4. 测试获取食物详情"
|
||||
# 请替换为实际的食物ID
|
||||
FOOD_ID="1"
|
||||
curl -X GET "$BASE_URL/food-library/$FOOD_ID" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json"
|
||||
|
||||
echo -e "\n\n5. 测试删除用户自定义食物"
|
||||
# 请替换为实际的自定义食物ID
|
||||
CUSTOM_FOOD_ID="1"
|
||||
curl -X DELETE "$BASE_URL/food-library/custom/$CUSTOM_FOOD_ID" \
|
||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-H "Content-Type: application/json"
|
||||
|
||||
echo -e "\n\n=== 测试完成 ==="
|
||||
Reference in New Issue
Block a user