Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

test: add destroy post tests for status filters and redirect param

Paulo Castellano6fc9defb898c
diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.php
index 8d460d652..eaefc21f6 100644
--- a/tests/Feature/PostControllerTest.php
+++ b/tests/Feature/PostControllerTest.php
@@ -241,7 +241,7 @@ test('destroy post requires authentication', function () {
$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 @@ test('destroy post deletes the post', function () {
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([