6 - Add admin instances page listing url and last poll

This commit is contained in:
myrmidex 2026-04-28 18:48:20 +02:00
parent 9cecc47b8b
commit 6e097acf88
5 changed files with 107 additions and 0 deletions

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
use Lvl0\FediDiscover\Models\Instance;
class InstancesController extends Controller
{
public function index(): View
{
$instances = Instance::orderBy('url', 'asc')->get();
return view('admin.index', ['instances' => $instances]);
}
}

View file

@ -0,0 +1,22 @@
<x-layout>
<div>
<h1>Instances</h1>
<table>
<thead>
<tr>
<th>Instance</th>
<th>Last polled at</th>
</tr>
</thead>
<tbody>
@foreach($instances as $instance)
<tr>
<td>{{ $instance->url }}</td>
<td>{{ $instance->last_polled_at }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</x-layout>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>{{ $title ?? 'Trove' }}</title>
</head>
<body>
{{ $slot }}
</body>
</html>

View file

@ -2,6 +2,7 @@
declare(strict_types=1);
use App\Http\Controllers\Admin\InstancesController;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
@ -11,3 +12,5 @@
Route::view('/submit', 'urls.submit');
Route::view('/bot', 'bot');
Route::get('/admin/instances', [InstancesController::class, 'index'])->name('admin.instances');

View file

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\Admin;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Lvl0\FediDiscover\Config\InstanceType;
use Lvl0\FediDiscover\Models\Instance;
use Tests\TestCase;
class InstancesAdminPageTest extends TestCase
{
use RefreshDatabase;
// -------------------------------------------------------------------------
// Test 3 — admin instances page is accessible
// -------------------------------------------------------------------------
public function test_admin_instances_page_is_accessible(): void
{
$response = $this->get('/admin/instances');
$response->assertStatus(200);
}
// -------------------------------------------------------------------------
// Test 4 — admin instances page lists each instance's URL and last_polled_at
// -------------------------------------------------------------------------
public function test_admin_instances_page_shows_each_instance_url_and_last_polled_at(): void
{
$mastodon = Instance::factory()
->type(InstanceType::Mastodon)
->enabled()
->create([
'url' => 'https://mastodon.social',
'last_polled_at' => '2024-06-01 12:00:00',
]);
$lemmy = Instance::factory()
->type(InstanceType::Lemmy)
->enabled()
->create([
'url' => 'https://lemmy.world',
'last_polled_at' => '2024-06-01 13:00:00',
]);
$response = $this->get('/admin/instances');
$response->assertSee($mastodon->url);
$response->assertSee($lemmy->url);
$response->assertSee($mastodon->last_polled_at->toDateString());
$response->assertSee($lemmy->last_polled_at->toDateString());
}
}