Add extensive controller and model tests
This commit is contained in:
29
tests/Feature/SystemUpdateControllerTest.php
Normal file
29
tests/Feature/SystemUpdateControllerTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
it('forbids system update for non-admins', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
$response = $this->postJson('/api/system/update');
|
||||
|
||||
$response->assertStatus(403);
|
||||
});
|
||||
|
||||
it('returns validation error when gitea config is missing', function (): void {
|
||||
putenv('GITEA_OWNER=');
|
||||
putenv('GITEA_REPO=');
|
||||
|
||||
$admin = User::factory()->create();
|
||||
$role = Role::firstOrCreate(['name' => 'ROLE_ADMIN'], ['color' => '#111111']);
|
||||
$admin->roles()->attach($role);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
$response = $this->postJson('/api/system/update');
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonFragment(['message' => 'Missing Gitea configuration.']);
|
||||
});
|
||||
Reference in New Issue
Block a user