File size: 3,109 Bytes
fcf2812 dc8cb49 fcf2812 96f3b64 64075d7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | from app.whatsapp.trip_selection import format_trip_card
def test_format_trip_card():
trip = {
"id": "trip-1",
"departure": "صنعاء",
"destination": "تعز",
"departure_date": "2026-12-01",
"departure_time": "noon",
"available_seats": 3,
"total_seats": 4,
"price": 5000,
"driver_cars": [{"car_type": "باص"}],
"drivers": [{"name": "أحمد"}],
"selection_count": 2,
}
card = format_trip_card(trip)
assert "صنعاء" in card
assert "تعز" in card
assert "2026-12-01" in card
assert "ظهرا" in card
assert "3 من 4" in card
assert "5000" in card
assert "باص" in card
assert "أحمد" in card
assert "2" in card
def test_format_trip_card_driver_message():
trip = {
"id": "trip-1",
"departure": "صنعاء",
"destination": "تعز",
"departure_date": "2026-12-01",
"departure_time": "noon",
"available_seats": 3,
"total_seats": 4,
"price": 5000,
"driver_cars": [{"car_type": "باص"}],
"drivers": [{"name": "أحمد"}],
"use_driver_message": True,
"driver_message": "باص من صنعاء الى تعز 😊😊😊",
}
card = format_trip_card(trip)
assert card == "باص من صنعاء الى تعز 😊😊😊"
assert "صنعاء ← إلى" not in card
def test_format_trip_card_driver_message_flag_false():
trip = {
"id": "trip-1",
"departure": "صنعاء",
"destination": "تعز",
"departure_date": "2026-12-01",
"departure_time": "noon",
"available_seats": 3,
"total_seats": 4,
"price": 5000,
"driver_cars": [{"car_type": "باص"}],
"drivers": [{"name": "أحمد"}],
"use_driver_message": False,
"driver_message": "باص من صنعاء الى تعز 😊😊😊",
}
card = format_trip_card(trip)
assert "صنعاء ← إلى" in card
def test_format_trip_card_driver_message_empty():
trip = {
"id": "trip-1",
"departure": "صنعاء",
"destination": "تعز",
"departure_date": "2026-12-01",
"departure_time": "noon",
"available_seats": 3,
"total_seats": 4,
"price": 5000,
"driver_cars": [{"car_type": "باص"}],
"drivers": [{"name": "أحمد"}],
"use_driver_message": True,
"driver_message": "",
}
card = format_trip_card(trip)
assert "صنعاء ← إلى" in card
def test_format_trip_card_null_seats():
trip = {
"id": "trip-1",
"departure": "صنعاء",
"destination": "تعز",
"departure_date": "2026-12-01",
"departure_time": "noon",
"available_seats": None,
"total_seats": None,
"price": 5000,
"driver_cars": [{"car_type": "باص"}],
"drivers": [{"name": "أحمد"}],
}
card = format_trip_card(trip)
assert "غير متوفرة" in card
assert "المقاعد:" in card
|