Added usage check to delete endpoints

This commit is contained in:
Constantin Graf
2024-04-18 21:42:29 +02:00
committed by Constantin Graf
parent 40f1159ea5
commit ad6146c483
18 changed files with 326 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ namespace Tests\Unit\Endpoint\Api\V1;
use App\Models\Client;
use App\Models\Organization;
use App\Models\Project;
use Illuminate\Testing\Fluent\AssertableJson;
use Laravel\Passport\Passport;
@@ -199,6 +200,27 @@ class ClientEndpointTest extends ApiEndpointTestAbstract
]);
}
public function test_destroy_endpoint_fails_if_client_is_still_in_use_by_project(): void
{
// Arrange
$data = $this->createUserWithPermission([
'clients:delete',
]);
$client = Client::factory()->forOrganization($data->organization)->create();
$project = Project::factory()->forOrganization($data->organization)->forClient($client)->create();
Passport::actingAs($data->user);
// Act
$response = $this->deleteJson(route('api.v1.clients.destroy', [$data->organization->getKey(), $client->getKey()]));
// Assert
$response->assertStatus(400);
$response->assertJsonPath('message', 'The client is still used by a project and can not be deleted.');
$this->assertDatabaseHas(Client::class, [
'id' => $client->getKey(),
]);
}
public function test_destroy_endpoint_deletes_client(): void
{
// Arrange