create([ 'creator_id' => $creator->id, 'title' => 'Pending Story ' . Str::random(6), 'slug' => 'pending-story-' . Str::lower(Str::random(8)), 'content' => '
Pending review content
', 'story_type' => 'creator_story', 'status' => 'pending_review', 'submitted_for_review_at' => now(), ]); } it('non moderator cannot access admin stories review queue', function () { $user = User::factory()->create(['role' => 'user']); $this->actingAs($user) ->get(route('admin.stories.review')) ->assertStatus(403); }); it('admin can approve a pending story and notify creator', function () { Notification::fake(); $admin = User::factory()->create(['role' => 'admin']); $creator = User::factory()->create(); $story = createPendingReviewStory($creator); $response = $this->actingAs($admin) ->post(route('admin.stories.approve', ['story' => $story->id])); $response->assertRedirect(); $story->refresh(); expect($story->status)->toBe('published'); expect($story->reviewed_by_id)->toBe($admin->id); expect($story->reviewed_at)->not->toBeNull(); expect($story->published_at)->not->toBeNull(); Notification::assertSentTo($creator, StoryStatusNotification::class); }); it('moderator can reject a pending story with reason and notify creator', function () { Notification::fake(); $moderator = User::factory()->create(['role' => 'moderator']); $creator = User::factory()->create(); $story = createPendingReviewStory($creator); $response = $this->actingAs($moderator) ->post(route('admin.stories.reject', ['story' => $story->id]), [ 'reason' => 'Please remove promotional external links and resubmit.', ]); $response->assertRedirect(); $story->refresh(); expect($story->status)->toBe('rejected'); expect($story->reviewed_by_id)->toBe($moderator->id); expect($story->reviewed_at)->not->toBeNull(); expect($story->rejected_reason)->toContain('promotional external links'); Notification::assertSentTo($creator, StoryStatusNotification::class); });