feat: detach instead of delete participant
This commit is contained in:
parent
571daea8b0
commit
fba0942407
|
|
@ -3,13 +3,14 @@
|
|||
namespace App\Filament\Resources\Hunts\RelationManagers;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DetachAction;
|
||||
use Filament\Actions\DetachBulkAction;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ParticipantsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'participants';
|
||||
|
|
@ -51,11 +52,11 @@ class ParticipantsRelationManager extends RelationManager
|
|||
// Tables\Actions\AttachAction::make(),
|
||||
])
|
||||
->actions([
|
||||
DeleteAction::make(),
|
||||
DetachAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
DetachBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Hunts\Pages\EditHunts;
|
||||
use App\Filament\Resources\Hunts\RelationManagers\ParticipantsRelationManager;
|
||||
use App\Models\Hunts;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('detaches a participant from a hunt without deleting the user', function () {
|
||||
$admin = User::factory()->create([
|
||||
'role' => UserRole::ADMIN,
|
||||
]);
|
||||
|
||||
$hunt = Hunts::withoutSyncingToSearch(fn () => Hunts::factory()->create([
|
||||
'creator_id' => $admin->id,
|
||||
]));
|
||||
|
||||
$participant = User::factory()->create();
|
||||
|
||||
$hunt->participants()->attach($participant->id);
|
||||
|
||||
$this->actingAs($admin);
|
||||
|
||||
Livewire::test(ParticipantsRelationManager::class, [
|
||||
'ownerRecord' => $hunt,
|
||||
'pageClass' => EditHunts::class,
|
||||
])
|
||||
->assertTableActionExists('detach', record: $participant->getKey())
|
||||
->assertTableActionDoesNotExist('delete', record: $participant->getKey())
|
||||
->callTableAction('detach', $participant->getKey());
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $participant->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('hunt_participants', [
|
||||
'hunt_id' => $hunt->id,
|
||||
'user_id' => $participant->id,
|
||||
]);
|
||||
});
|
||||
Loading…
Reference in New Issue