""" Tests for Nutricore agent tools """ import pytest import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) import database @pytest.fixture(autouse=True) def setup_db(tmp_path): database.DB_PATH = str(tmp_path / "test.db") database.init_db() yield # ── browse_products ─────────────────────────────────────────────────────────── def test_browse_all_products(): from tools import browse_products_impl result = browse_products_impl() assert result["total"] == 12 assert len(result["products"]) == 12 assert len(result["categories"]) == 3 def test_browse_fruit_powders(): from tools import browse_products_impl result = browse_products_impl("Fruit Powders") assert result["total"] == 5 for p in result["products"]: assert "Fruit" in p["category"] def test_browse_vegetable_powders(): from tools import browse_products_impl result = browse_products_impl("Vegetable") assert result["total"] == 4 def test_browse_green_leaf_powders(): from tools import browse_products_impl result = browse_products_impl("Green") assert result["total"] == 3 def test_browse_empty_category_returns_all(): from tools import browse_products_impl result = browse_products_impl("") assert result["total"] == 12 # ── get_product_info ────────────────────────────────────────────────────────── def test_get_product_info_banana(): from tools import get_product_info_impl result = get_product_info_impl(1) assert result["name"] == "Banana Powder" assert result["price"] == 850 assert result["category"] == "Fruit Powders" assert "benefits" in result assert "nutrition" in result assert "how_to_use" in result def test_get_product_info_moringa(): from tools import get_product_info_impl result = get_product_info_impl(11) assert result["name"] == "Moringa Powder" assert result["price"] == 900 def test_get_product_info_not_found(): from tools import get_product_info_impl result = get_product_info_impl(999) assert "error" in result # ── find_product_for_goal ───────────────────────────────────────────────────── def test_find_products_for_weight_loss(): from tools import find_product_for_goal_impl result = find_product_for_goal_impl("weight_loss") assert "recommended_products" in result assert result["total"] > 0 assert result["health_goal"] == "weight_loss" def test_find_products_for_immunity(): from tools import find_product_for_goal_impl result = find_product_for_goal_impl("immunity") assert result["total"] > 0 def test_find_products_for_energy(): from tools import find_product_for_goal_impl result = find_product_for_goal_impl("energy") assert result["total"] > 0 def test_find_products_for_skin_health(): from tools import find_product_for_goal_impl result = find_product_for_goal_impl("skin_health") assert result["total"] > 0 def test_find_products_for_digestion(): from tools import find_product_for_goal_impl result = find_product_for_goal_impl("digestion") assert result["total"] > 0 def test_find_products_for_detox(): from tools import find_product_for_goal_impl result = find_product_for_goal_impl("detox") assert result["total"] > 0 # ── get_recipe_ideas ────────────────────────────────────────────────────────── def test_get_recipe_for_banana(): from tools import get_recipe_ideas_impl result = get_recipe_ideas_impl(1) assert result["product"] == "Banana Powder" assert len(result["recipes"]) > 0 def test_get_recipe_general(): from tools import get_recipe_ideas_impl result = get_recipe_ideas_impl(0) assert "recipes" in result assert len(result["recipes"]) > 0 def test_get_recipe_not_found(): from tools import get_recipe_ideas_impl result = get_recipe_ideas_impl(999) assert "error" in result # ── compare_products ────────────────────────────────────────────────────────── def test_compare_moringa_spinach(): from tools import compare_products_impl result = compare_products_impl(11, 10) assert "comparison" in result assert result["comparison"]["product_1"]["name"] == "Moringa Powder" assert result["comparison"]["product_2"]["name"] == "Spinach Powder" assert "price_difference" in result def test_compare_not_found(): from tools import compare_products_impl result = compare_products_impl(999, 1) assert "error" in result def test_compare_price_difference(): from tools import compare_products_impl result = compare_products_impl(1, 2) # 850 vs 950 assert result["price_difference"] == 100 assert result["cheaper"] == "Banana Powder" # ── check_price_and_delivery ────────────────────────────────────────────────── def test_check_price_lahore(): from tools import check_price_and_delivery_impl result = check_price_and_delivery_impl(1, "lahore") assert result["product"]["name"] == "Banana Powder" assert result["delivery"]["city"] == "Lahore" assert result["delivery"]["charge"] == 150 assert result["total_amount"] == 850 + 150 def test_check_price_karachi(): from tools import check_price_and_delivery_impl result = check_price_and_delivery_impl(1, "karachi") assert result["delivery"]["charge"] == 200 assert result["total_amount"] == 850 + 200 def test_check_price_unknown_city(): from tools import check_price_and_delivery_impl result = check_price_and_delivery_impl(1, "quetta") assert result["delivery"]["charge"] == 250 def test_check_price_product_not_found(): from tools import check_price_and_delivery_impl result = check_price_and_delivery_impl(999, "lahore") assert "error" in result # ── place_order ─────────────────────────────────────────────────────────────── def test_place_order_success(): from tools import place_order_impl result = place_order_impl( name="Ahmed Khan", phone="03001234567", address="House 12, DHA Phase 5, Lahore", products=[{"product_id": 1, "quantity": 2}, {"product_id": 11, "quantity": 1}] ) assert result["success"] is True assert "order_id" in result assert result["customer"] == "Ahmed Khan" assert len(result["items"]) == 2 def test_place_order_missing_name(): from tools import place_order_impl result = place_order_impl(name="", phone="03001234567", address="Lahore", products=[{"product_id": 1}]) assert "error" in result def test_place_order_missing_phone(): from tools import place_order_impl result = place_order_impl(name="Ahmed", phone="", address="Lahore", products=[{"product_id": 1}]) assert "error" in result def test_place_order_empty_products(): from tools import place_order_impl result = place_order_impl(name="Ahmed", phone="03001234567", address="Lahore", products=[]) assert "error" in result def test_place_order_calculates_total(): from tools import place_order_impl result = place_order_impl( name="Sara Ali", phone="03211234567", address="F-7, Islamabad", products=[{"product_id": 1, "quantity": 1}] # PKR 850 ) assert result["success"] is True # Total = 850 + delivery assert result["total_amount"] >= 850