97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?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();
|
|
});
|