From 6fc9defb898cb3ce0ee24008f351b165286d08cf Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Mon, 26 Jan 2026 14:00:37 -0300 Subject: [PATCH] test: add destroy post tests for status filters and redirect param --- tests/Feature/PostControllerTest.php | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.php index 8d460d65..eaefc21f 100644 --- a/tests/Feature/PostControllerTest.php +++ b/tests/Feature/PostControllerTest.php @@ -241,7 +241,7 @@ $response->assertRedirect(route('login')); }); -test('destroy post deletes the post', function () { +test('destroy post deletes the post and redirects back', function () { $post = Post::factory()->create([ 'workspace_id' => $this->workspace->id, 'user_id' => $this->user->id, @@ -255,6 +255,33 @@ expect(Post::find($post->id))->toBeNull(); }); +test('destroy post from status filter redirects back to filter', function (string $status) { + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + ]); + + $response = $this->actingAs($this->user) + ->from(route('posts.index', ['status' => $status])) + ->delete(route('posts.destroy', $post)); + + $response->assertRedirect(route('posts.index', ['status' => $status])); + expect(Post::find($post->id))->toBeNull(); +})->with(['draft', 'scheduled', 'published']); + +test('destroy post with redirect param redirects to specified route', function () { + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + ]); + + $response = $this->actingAs($this->user) + ->delete(route('posts.destroy', $post).'?redirect=posts.index'); + + $response->assertRedirect(route('posts.index')); + expect(Post::find($post->id))->toBeNull(); +}); + test('destroy post returns 404 for post from different workspace', function () { $otherWorkspace = Workspace::factory()->create(); $post = Post::factory()->create([