make(Illuminate\Contracts\Console\Kernel::class); $kernel->bootstrap(); use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Hash; use App\Models\User; echo "══════════════════════════════════════════\n"; echo " 🧪 IFNEX API Test Suite\n"; echo "══════════════════════════════════════════\n\n"; // ─── 0. تنظیم رمز عبور برای تست ───────────────────────────── $testEmail = 'kazem@vernasoft.group'; $testPassword = 'Test@12345'; $user = User::where('email', $testEmail)->first(); if (!$user) { echo "❌ کاربر {$testEmail} پیدا نشد!\n"; exit(1); } $user->password = Hash::make($testPassword); $user->save(); echo "✅ رمز کاربر {$user->name} به '{$testPassword}' تغییر یافت\n\n"; // ─── 1. تست Login ────────────────────────────────────────── echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; echo "تست ۱: دریافت توکن (Login)\n"; echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; $response = Http::post('http://localhost:8000/api/v1/auth/login', [ 'email' => $testEmail, 'password' => $testPassword, 'token_name' => 'test-api', ]); echo "Status: " . $response->status() . "\n"; $data = $response->json(); print_r($data); if ($response->status() !== 200 || !isset($data['token'])) { echo "\n❌ Login ناموفق بود! بقیه تست‌ها را نمی‌توان انجام داد.\n"; exit(1); } $token = $data['token']; echo "\n✅ Login موفق! توکن دریافت شد.\n\n"; // ─── 2. تست Profile ──────────────────────────────────────── echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; echo "تست ۲: دریافت پروفایل\n"; echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; $response2 = Http::withToken($token) ->get('http://localhost:8000/api/v1/customer/profile'); echo "Status: " . $response2->status() . "\n"; print_r($response2->json()); echo "\n"; // ─── 3. تست Countries ────────────────────────────────────── echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; echo "تست ۳: لیست کشورها\n"; echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; $response3 = Http::withToken($token) ->get('http://localhost:8000/api/v1/customer/countries'); echo "Status: " . $response3->status() . "\n"; $countries = $response3->json(); echo "تعداد کشورها: " . (isset($countries['data']) ? count($countries['data']) : 0) . "\n"; if (isset($countries['data']) && count($countries['data']) > 0) { echo "اولین کشور: " . print_r($countries['data'][0], true) . "\n"; } echo "\n"; // ─── 4. تست ساخت سفارش ──────────────────────────────────── echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; echo "تست ۴: ثبت سفارش جدید\n"; echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; $orderData = [ 'direction' => 'export', 'type' => 'PARCEL', 'from_country_id' => 1, 'to_country_id' => 2, 'weight' => 2.5, 'volumetric_weight' => 3, 'sender_name' => 'Kazem Test', 'sender_phone' => '09123456789', 'sender_address' => 'Tehran, Valiasr St.', 'sender_city' => 'Tehran', 'receiver_name' => 'Ali Customer', 'receiver_phone' => '+971501234567', 'receiver_address' => 'Dubai, Marina', 'receiver_city' => 'Dubai', ]; $response4 = Http::withToken($token) ->post('http://localhost:8000/api/v1/customer/orders', $orderData); echo "Status: " . $response4->status() . "\n"; $orderResult = $response4->json(); print_r($orderResult); echo "\n"; // ─── 5. تست لیست سفارشات ─────────────────────────────────── echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; echo "تست ۵: لیست سفارشات کاربر\n"; echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"; $response5 = Http::withToken($token) ->get('http://localhost:8000/api/v1/customer/orders'); echo "Status: " . $response5->status() . "\n"; $orders = $response5->json(); echo "تعداد سفارشات: " . (isset($orders['data']) ? count($orders['data']) : 0) . "\n"; if (isset($orders['data']) && count($orders['data']) > 0) { echo "اولین سفارش: AWB = " . ($orders['data'][0]['awb_no'] ?? '—') . "\n"; } echo "\n"; // ─── جمع‌بندی ─────────────────────────────────────────────── echo "══════════════════════════════════════════\n"; echo " 🎯 نتیجه نهایی\n"; echo "══════════════════════════════════════════\n"; echo "Login: " . ($response->status() === 200 ? "✅" : "❌") . "\n"; echo "Profile: " . ($response2->status() === 200 ? "✅" : "❌") . "\n"; echo "Countries: " . ($response3->status() === 200 ? "✅" : "❌") . "\n"; echo "Create Order:" . ($response4->status() === 201 ? "✅" : "❌") . "\n"; echo "List Orders: " . ($response5->status() === 200 ? "✅" : "❌") . "\n"; echo "══════════════════════════════════════════\n";