create(); $otherUser = User::factory()->create(); $unreadNotifications = collect([ $this->createNotification($user->id), $this->createNotification($user->id), ]); $alreadyReadAt = now()->subDay(); $alreadyReadNotification = $this->createNotification($user->id, $alreadyReadAt); $otherUserNotification = $this->createNotification($otherUser->id); $response = $this->actingAs($user)->postJson(route('notifications.read-all')); $response ->assertOk() ->assertJson([ 'ok' => true, 'updated' => 2, 'unread' => 0, ]); foreach ($unreadNotifications as $notification) { $this->assertNotNull($notification->fresh()->read_at); } $this->assertSame( $alreadyReadAt->format('Y-m-d H:i:s'), $alreadyReadNotification->fresh()->read_at?->format('Y-m-d H:i:s') ); $this->assertNull($otherUserNotification->fresh()->read_at); } private function createNotification(int $userId, $readAt = null): UserNotification { return UserNotification::query()->create([ 'user_id' => $userId, 'type' => UserNotification::TYPE_PLATFORM, 'event' => UserNotification::EVENT_CREATED, 'title' => 'Тестовое уведомление', 'message' => 'Тестовое сообщение', 'message_html' => '
Тестовое сообщение
', 'read_at' => $readAt, ]); } }