Lance Pioch f8ad9a1805
Use PestPHP (#962)
* Install Pest

* Don’t use bootstrap file anymore

* Fix comment

* Think this is needed

* Reset this

* Switch dataproviders to attributes

* Fix these

* Support in memory databases

* Fix this migration

* Switch this back for now

* Add missing import

* Truncate and reseed database

* These are replaced now

* Switch ci to use pest
2025-01-30 16:39:17 -05:00

85 lines
3.0 KiB
PHP

<?php
namespace App\Tests\Integration\Api\Client\Server\Schedule;
use App\Models\Task;
use Illuminate\Http\Response;
use App\Models\Schedule;
use App\Models\Permission;
use App\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
{
/**
* Test that a schedule can be deleted from the system.
*/
#[DataProvider('permissionsDataProvider')]
public function testScheduleCanBeDeleted(array $permissions): void
{
[$user, $server] = $this->generateTestAccount($permissions);
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
$task = Task::factory()->create(['schedule_id' => $schedule->id]);
$this->actingAs($user)
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
->assertStatus(Response::HTTP_NO_CONTENT);
$this->assertDatabaseMissing('schedules', ['id' => $schedule->id]);
$this->assertDatabaseMissing('tasks', ['id' => $task->id]);
}
/**
* Test that no error is returned if the schedule does not exist on the system at all.
*/
public function testNotFoundErrorIsReturnedIfScheduleDoesNotExistAtAll(): void
{
[$user, $server] = $this->generateTestAccount();
$this->actingAs($user)
->deleteJson("/api/client/servers/$server->uuid/schedules/123456789")
->assertStatus(Response::HTTP_NOT_FOUND);
}
/**
* Ensure that a schedule belonging to another server cannot be deleted and its presence is not
* revealed to the user.
*/
public function testNotFoundErrorIsReturnedIfScheduleDoesNotBelongToServer(): void
{
[$user, $server] = $this->generateTestAccount();
$server2 = $this->createServerModel(['owner_id' => $user->id]);
$schedule = Schedule::factory()->create(['server_id' => $server2->id]);
$this->actingAs($user)
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
->assertStatus(Response::HTTP_NOT_FOUND);
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
}
/**
* Test that an error is returned if the subuser does not have the required permissions to
* delete the schedule from the server.
*/
public function testErrorIsReturnedIfSubuserDoesNotHaveRequiredPermissions(): void
{
[$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_UPDATE]);
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
$this->actingAs($user)
->deleteJson("/api/client/servers/$server->uuid/schedules/$schedule->id")
->assertStatus(Response::HTTP_FORBIDDEN);
$this->assertDatabaseHas('schedules', ['id' => $schedule->id]);
}
public static function permissionsDataProvider(): array
{
return [[[]], [[Permission::ACTION_SCHEDULE_DELETE]]];
}
}