more fixes
This commit is contained in:
76
tests/Feature/Stories/AdminStoryModerationWorkflowTest.php
Normal file
76
tests/Feature/Stories/AdminStoryModerationWorkflowTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Story;
|
||||
use App\Models\User;
|
||||
use App\Notifications\StoryStatusNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
function createPendingReviewStory(User $creator): Story
|
||||
{
|
||||
return Story::query()->create([
|
||||
'creator_id' => $creator->id,
|
||||
'title' => 'Pending Story ' . Str::random(6),
|
||||
'slug' => 'pending-story-' . Str::lower(Str::random(8)),
|
||||
'content' => '<p>Pending review content</p>',
|
||||
'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);
|
||||
});
|
||||
96
tests/Feature/Stories/CreatorStoryWorkflowTest.php
Normal file
96
tests/Feature/Stories/CreatorStoryWorkflowTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Story;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
function storyPayload(array $overrides = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'title' => 'Story ' . Str::random(8),
|
||||
'cover_image' => 'https://example.test/cover.jpg',
|
||||
'excerpt' => 'A compact excerpt for testing.',
|
||||
'story_type' => 'creator_story',
|
||||
'content' => '<p>Hello Story World</p>',
|
||||
'status' => 'draft',
|
||||
'submit_action' => 'save_draft',
|
||||
], $overrides);
|
||||
}
|
||||
|
||||
it('creator can create a draft story from editor form', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($creator)
|
||||
->post(route('creator.stories.store'), storyPayload());
|
||||
|
||||
$story = Story::query()->where('creator_id', $creator->id)->latest('id')->first();
|
||||
|
||||
expect($story)->not->toBeNull();
|
||||
expect($story->status)->toBe('draft');
|
||||
expect($story->slug)->not->toBe('');
|
||||
|
||||
$response->assertRedirect(route('creator.stories.edit', ['story' => $story->id]));
|
||||
});
|
||||
|
||||
it('creator autosave updates draft fields and creates tags from csv', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$story = Story::query()->create([
|
||||
'creator_id' => $creator->id,
|
||||
'title' => 'Autosave Draft',
|
||||
'slug' => 'autosave-draft-' . Str::lower(Str::random(6)),
|
||||
'content' => '<p>Original</p>',
|
||||
'story_type' => 'creator_story',
|
||||
'status' => 'draft',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($creator)->postJson(
|
||||
route('creator.stories.autosave', ['story' => $story->id]),
|
||||
[
|
||||
'title' => 'Autosaved Title',
|
||||
'content' => '<p>Autosaved content with enough words for reading time.</p>',
|
||||
'tags_csv' => 'alpha,beta',
|
||||
]
|
||||
);
|
||||
|
||||
$response->assertOk()->assertJson(['ok' => true]);
|
||||
|
||||
$story->refresh();
|
||||
|
||||
expect($story->title)->toBe('Autosaved Title');
|
||||
expect($story->status)->toBe('draft');
|
||||
|
||||
$this->assertDatabaseHas('story_tags', ['slug' => 'alpha']);
|
||||
$this->assertDatabaseHas('story_tags', ['slug' => 'beta']);
|
||||
|
||||
$tagIds = DB::table('story_tags')->whereIn('slug', ['alpha', 'beta'])->pluck('id')->all();
|
||||
foreach ($tagIds as $tagId) {
|
||||
$this->assertDatabaseHas('relation_story_tags', [
|
||||
'story_id' => $story->id,
|
||||
'tag_id' => $tagId,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it('creator can submit draft for review', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$story = Story::query()->create([
|
||||
'creator_id' => $creator->id,
|
||||
'title' => 'Review Draft',
|
||||
'slug' => 'review-draft-' . Str::lower(Str::random(6)),
|
||||
'content' => '<p>Review content</p>',
|
||||
'story_type' => 'creator_story',
|
||||
'status' => 'draft',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($creator)
|
||||
->post(route('creator.stories.submit-review', ['story' => $story->id]));
|
||||
|
||||
$response->assertRedirect();
|
||||
|
||||
$story->refresh();
|
||||
expect($story->status)->toBe('pending_review');
|
||||
expect($story->submitted_for_review_at)->not->toBeNull();
|
||||
});
|
||||
Reference in New Issue
Block a user