Skip to content

Commit eacff0d

Browse files
committed
wip
1 parent 7a86dbf commit eacff0d

3 files changed

Lines changed: 97 additions & 6 deletions

File tree

database/factories/LogFileFactory.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
22

33
namespace Database\Factories;
44

5+
use App\Models\Application;
6+
use App\Watchtower\Alerts\LogLevel;
57
use Illuminate\Database\Eloquent\Factories\Factory;
68

79
class LogFileFactory extends Factory
810
{
911
public function definition(): array
1012
{
1113
return [
12-
//
14+
// 'server_id'
15+
// 'application_id'
16+
'file_name' => str_uuid().'.log',
17+
'file_size_in_bytes' => mt_rand(100, 100_000_000),
18+
'new_highest_log_level' => LogLevel::error,
19+
'last_modified_at' => now(),
20+
'last_seen_at' => now(),
21+
'created_at' => now(),
22+
'updated_at' => now(),
1323
];
1424
}
25+
26+
public function forApplication(Application $application)
27+
{
28+
return $this->state(function (array $attributes) use ($application) {
29+
return [
30+
'server_id' => $application->server_id,
31+
'application_id' => $application->id,
32+
];
33+
});
34+
}
1535
}

routes/web-user-routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
use Illuminate\Support\Facades\Route;
55

66
Route::get('/', [DashboardController::class, 'get'])->name('dashboard');
7-
Route::get('/{serverSlug}/{applicationSlug}', [DashboardController::class, 'showTwo']);
8-
Route::get('/{serverSlug}/{applicationSlug}/{fileName}', [DashboardController::class, 'ShowThree']);
7+
Route::get('/{serverSlug}/{applicationSlug}', [DashboardController::class, 'showTwo'])->name('dashboard.show-two');
8+
Route::get('/{serverSlug}/{applicationSlug}/{fileName}', [DashboardController::class, 'ShowThree'])->name('dashboard.show-three');

tests/Unit/Controllers/DashboardControllerTest.php

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Tests\Unit\Controllers;
44

5+
use App\Models\Application;
6+
use App\Models\LogFile;
7+
use App\Models\Server;
8+
use App\Models\User;
59
use PHPUnit\Framework\Attributes\Test;
610
use Tests\TestCase;
711

@@ -10,18 +14,85 @@ class DashboardControllerTest extends TestCase
1014
#[Test]
1115
public function you_must_be_logged_in_to_see_the_dashboard()
1216
{
13-
//
17+
$this->assertGuest();
18+
19+
$this->get(route('dashboard'))
20+
->assertRedirectToRoute('login');
1421
}
1522

1623
#[Test]
1724
public function it_can_show_the_empty_dashboard()
1825
{
19-
//
26+
$user = User::factory()->create();
27+
28+
$this->actingAs($user)
29+
->get(route('dashboard'))
30+
->assertStatus(200);
2031
}
2132

2233
#[Test]
2334
public function it_can_show_the_dashboard()
2435
{
25-
//
36+
$user = User::factory()->create();
37+
38+
$server1 = Server::factory()->create();
39+
$application1 = Application::factory()->create(['server_id' => $server1->id]);
40+
$application2 = Application::factory()->create(['server_id' => $server1->id]);
41+
42+
$server2 = Server::factory()->create();
43+
$application3 = Application::factory()->create(['server_id' => $server2->id]);
44+
45+
$this->actingAs($user)
46+
->get(route('dashboard'))
47+
->assertStatus(200)
48+
->assertSee($server1->name)
49+
->assertSee($server2->name)
50+
->assertSee($application1->name)
51+
->assertSee($application2->name)
52+
->assertSee($application3->name);
53+
}
54+
55+
#[Test]
56+
public function it_can_show_the_dashboard__modal_one_deep()
57+
{
58+
$user = User::factory()->create();
59+
60+
$server1 = Server::factory()->create();
61+
$application1 = Application::factory()->create(['server_id' => $server1->id]);
62+
$application2 = Application::factory()->create(['server_id' => $server1->id]);
63+
64+
$this->actingAs($user)
65+
->get(route('dashboard.show-two', [$server1->slug, $application1->slug]))
66+
->assertStatus(200);
67+
}
68+
69+
#[Test]
70+
public function it_can_show_the_dashboard__modal_two_deep()
71+
{
72+
$user = User::factory()->create();
73+
74+
$server1 = Server::factory()->create();
75+
$application1 = Application::factory()->create(['server_id' => $server1->id]);
76+
$application2 = Application::factory()->create(['server_id' => $server1->id]);
77+
78+
$logFile = LogFile::factory()->forApplication($application2)->create();
79+
80+
$this->actingAs($user)
81+
->get(route('dashboard.show-three', [$application2->server->slug, $application2->slug, $logFile->file_name]))
82+
->assertStatus(200);
83+
}
84+
85+
#[Test]
86+
public function it_can_show_the_dashboard__modal_redirects_if_log_does_not_exist()
87+
{
88+
$user = User::factory()->create();
89+
90+
$application = Application::factory()->create();
91+
92+
$logFile = LogFile::factory()->forApplication($application)->create();
93+
94+
$this->actingAs($user)
95+
->get(route('dashboard.show-three', [$application->server->slug, $application->slug, 'some-other-file.log']))
96+
->assertRedirectToRoute('dashboard');
2697
}
2798
}

0 commit comments

Comments
 (0)