Repair: copy legacy joinDate into new user's created_at when creating users from legacy wallz

This commit is contained in:
2026-03-22 09:13:39 +01:00
parent e8b5edf5d2
commit 2608be7420
80 changed files with 3991 additions and 723 deletions

View File

@@ -12,8 +12,10 @@ use App\Policies\ConversationPolicy;
use App\Events\ConversationUpdated;
use App\Events\MessageCreated;
use App\Events\MessageRead;
use App\Services\Messaging\MessagingPresenceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
@@ -259,6 +261,133 @@ test('typing endpoints reject non participants', function () {
->assertStatus(403);
});
test('conversation list includes unread summary total', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread one',
]);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread two',
]);
$response = $this->actingAs($userA)->getJson('/api/messages/conversations');
$response->assertStatus(200)
->assertJsonPath('summary.unread_total', 2);
});
test('conversation updated broadcast includes unread summary total', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread one',
]);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread two',
]);
$payload = (new ConversationUpdated($userA->id, $conv->fresh(), 'message.created'))->broadcastWith();
expect($payload['reason'])->toBe('message.created')
->and((int) data_get($payload, 'conversation.id'))->toBe($conv->id)
->and((int) data_get($payload, 'conversation.unread_count'))->toBe(2)
->and((int) data_get($payload, 'summary.unread_total'))->toBe(2);
});
test('delta endpoint returns only messages after requested id in ascending order', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
$first = Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'First',
]);
$second = Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Second',
]);
$third = Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userA->id,
'body' => 'Third',
]);
$response = $this->actingAs($userA)->getJson("/api/messages/{$conv->id}/delta?after_message_id={$first->id}");
$response->assertStatus(200)
->assertJsonPath('data.0.id', $second->id)
->assertJsonPath('data.1.id', $third->id);
});
test('presence heartbeat marks user online and viewing a conversation', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
$this->actingAs($userA)
->postJson('/api/messages/presence/heartbeat', ['conversation_id' => $conv->id])
->assertStatus(200)
->assertJsonFragment(['conversation_id' => $conv->id]);
$presence = app(MessagingPresenceService::class);
expect($presence->isUserOnline($userA->id))->toBeTrue()
->and($presence->isViewingConversation($conv->id, $userA->id))->toBeTrue();
});
test('offline fallback notifications are skipped for online recipients', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
app(MessagingPresenceService::class)->touch($userB);
$this->actingAs($userA)->postJson("/api/messages/{$conv->id}", [
'body' => 'Presence-aware hello',
])->assertStatus(201);
expect(DB::table('notifications')->count())->toBe(0);
});
test('offline fallback notifications are stored for offline recipients', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
$this->actingAs($userA)->postJson("/api/messages/{$conv->id}", [
'body' => 'Offline hello',
])->assertStatus(201);
$notification = DB::table('notifications')->first();
expect($notification)->not->toBeNull()
->and((int) $notification->user_id)->toBe($userB->id)
->and((string) $notification->type)->toBe('message');
});
test('report endpoint creates moderation report entry', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();