FilamentF
Filamentβ€’3y ago
Gunnolfson

Cannot delete test

Hi

I wonder what's the easiest and most maintenable way of checking something cannot be deleted from a testing point of view. I mean, testing it is not possible from "bulking action", "table action", "page action" etc requires, imo, too much test code.

I would rather look for something unique, that would look like this:
test('admin cannot delete', function () {
    $admin = AdminUserFactory::new()->create();

    $thing = ThingFactory::new()->create();

    actingAs($admin, 'admin')
        ->delete(ThingResource::getUrl('delete', ['record' => $thing->getRouteKey()]))
        ->assertForbidden();
});


I've been adviced to use a Laravel policy to implement it. Fair enough but it is not what's relevant here. For some reasons we might not want to use a policy, and the test should be as abstract as possible from the implementations. What I mean is I don't want to have a test on a policy, but rather a "Filament test" that is more close to the feature spec than the code itself

Thanks πŸ™ if you have any information about this. Moved to a help post as it's not as simple as I though initially πŸ˜…
Was this page helpful?