create(); $investigation = Investigation::factory()->for($owner, 'owner')->create(); $target = $investigation->targets()->create([ 'type' => 'username', 'value' => 'someone', 'created_by' => $owner->id, ]); $this->actingAs($owner) ->delete(route('investigations.destroy', $investigation)) ->assertRedirect(route('investigations.index')); $this->assertDatabaseMissing('investigations', ['id' => $investigation->id]); $this->assertDatabaseMissing('targets', ['id' => $target->id]); } public function test_editor_cannot_delete_investigation(): void { $owner = User::factory()->create(); $editor = User::factory()->create(); $investigation = Investigation::factory()->for($owner, 'owner')->create(); $investigation->users()->attach($editor, ['role' => 'editor']); $this->actingAs($editor) ->delete(route('investigations.destroy', $investigation)) ->assertForbidden(); $this->assertDatabaseHas('investigations', ['id' => $investigation->id]); } }