-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.php
More file actions
161 lines (137 loc) Β· 5.42 KB
/
Copy pathtest_api.php
File metadata and controls
161 lines (137 loc) Β· 5.42 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env php
<?php
/**
* Quick API Test Script
* Run this to verify your chat app API is working correctly
*
* Usage: php test_api.php
*/
require __DIR__.'/vendor/autoload.php';
use Illuminate\Support\Facades\Artisan;
$app = require_once __DIR__.'/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
echo "π§ͺ Chat App API Test\n";
echo str_repeat("=", 50) . "\n\n";
// Test 1: Check if users exist
echo "1οΈβ£ Checking users...\n";
$userCount = \App\Models\User::count();
echo " β
Found $userCount users in database\n";
if ($userCount > 0) {
$sampleUser = \App\Models\User::first();
echo " π€ Sample user: {$sampleUser->name} ({$sampleUser->email})\n";
}
echo "\n";
// Test 2: Search functionality
echo "2οΈβ£ Testing user search...\n";
if ($userCount >= 2) {
$searchTerm = substr(\App\Models\User::skip(1)->first()->name, 0, 3);
$results = \App\Models\User::where('name', 'like', "%{$searchTerm}%")->limit(5)->get();
echo " π Search for '{$searchTerm}': Found {$results->count()} users\n";
foreach ($results as $user) {
echo " - {$user->name} ({$user->email})\n";
}
} else {
echo " β οΈ Need at least 2 users to test search\n";
}
echo "\n";
// Test 3: Check conversations
echo "3οΈβ£ Checking conversations...\n";
$conversationCount = \App\Models\Conversation::count();
echo " β
Found $conversationCount conversations\n";
if ($conversationCount > 0) {
$sampleConv = \App\Models\Conversation::with('participants')->first();
$participantNames = $sampleConv->participants->pluck('name')->join(', ');
echo " π¬ Sample conversation: {$sampleConv->name} (Participants: {$participantNames})\n";
}
echo "\n";
// Test 4: Check messages
echo "4οΈβ£ Checking messages...\n";
$messageCount = \App\Models\Message::count();
echo " β
Found $messageCount messages\n";
if ($messageCount > 0) {
$sampleMsg = \App\Models\Message::with('sender')->latest()->first();
$preview = substr($sampleMsg->body ?? '[image]', 0, 50);
echo " π¨ Latest message: \"{$preview}\" (from {$sampleMsg->sender->name})\n";
echo " π¨ Message fields: id={$sampleMsg->id}, body=" . ($sampleMsg->body ? "'{$sampleMsg->body}'" : 'null') . ", type={$sampleMsg->type}\n";
}
echo "\n";
// Test 5: Check message structure
if ($messageCount > 0) {
echo "5οΈβ£ Testing message API response structure...\n";
$testMessage = \App\Models\Message::with(['sender', 'media'])->first();
$jsonResponse = $testMessage->toArray();
$requiredFields = ['id', 'conversation_id', 'user_id', 'body', 'type', 'created_at', 'sender'];
$missing = [];
foreach ($requiredFields as $field) {
if (!array_key_exists($field, $jsonResponse)) {
$missing[] = $field;
}
}
if (empty($missing)) {
echo " β
All required fields present in message response\n";
echo " π Fields: " . implode(', ', array_keys($jsonResponse)) . "\n";
} else {
echo " β Missing fields: " . implode(', ', $missing) . "\n";
}
// Check sender structure
if (isset($jsonResponse['sender'])) {
$senderFields = array_keys($jsonResponse['sender']);
echo " π€ Sender fields: " . implode(', ', $senderFields) . "\n";
// Check for avatar_url
if (in_array('avatar_url', $senderFields)) {
echo " β
avatar_url accessor is present\n";
} else {
echo " β οΈ avatar_url accessor is missing (check User model \$appends)\n";
}
}
}
echo "\n";
// Test 6: Storage link
echo "6οΈβ£ Checking storage link...\n";
$storagePath = public_path('storage');
if (file_exists($storagePath)) {
if (is_link($storagePath)) {
echo " β
Storage link exists\n";
} else {
echo " β οΈ Storage directory exists but is not a symlink\n";
}
} else {
echo " β Storage link missing - Run: php artisan storage:link\n";
}
echo "\n";
// Test 7: Broadcasting configuration
echo "7οΈβ£ Checking broadcasting config...\n";
$broadcastDriver = config('broadcasting.default');
echo " π‘ Broadcast driver: {$broadcastDriver}\n";
if ($broadcastDriver === 'reverb') {
$reverbConfig = config('broadcasting.connections.reverb');
echo " β
Reverb configured\n";
echo " - App ID: {$reverbConfig['app_id']}\n";
echo " - Host: {$reverbConfig['options']['host']}:{$reverbConfig['options']['port']}\n";
echo " - Scheme: {$reverbConfig['options']['scheme']}\n";
} else {
echo " β οΈ Broadcast driver is '{$broadcastDriver}' (expected 'reverb')\n";
}
echo "\n";
// Summary
echo str_repeat("=", 50) . "\n";
echo "π Summary:\n";
echo " - Users: {$userCount}\n";
echo " - Conversations: {$conversationCount}\n";
echo " - Messages: {$messageCount}\n";
echo "\n";
if ($userCount === 0) {
echo "β οΈ WARNING: No users found! Create users first:\n";
echo " php artisan tinker\n";
echo " >>> User::factory()->count(3)->create();\n";
echo "\n";
}
if ($conversationCount === 0 && $userCount >= 2) {
echo "π‘ TIP: Create a test conversation in the Flutter app or via tinker:\n";
echo " \$user1 = User::first();\n";
echo " \$user2 = User::skip(1)->first();\n";
echo " \$conv = Conversation::create(['type' => 'direct', 'name' => null]);\n";
echo " \$conv->participants()->attach([\$user1->id, \$user2->id]);\n";
echo "\n";
}
echo "β
API test complete!\n";