update
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ActivityEvent;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Story;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -94,3 +96,135 @@ it('creator can submit draft for review', function () {
|
||||
expect($story->status)->toBe('pending_review');
|
||||
expect($story->submitted_for_review_at)->not->toBeNull();
|
||||
});
|
||||
|
||||
it('creator publish records story activity and stores a story_published notification', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$story = Story::query()->create([
|
||||
'creator_id' => $creator->id,
|
||||
'title' => 'Publish Me',
|
||||
'slug' => 'publish-me-' . Str::lower(Str::random(6)),
|
||||
'content' => '<p>Publish content</p>',
|
||||
'story_type' => 'creator_story',
|
||||
'status' => 'draft',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($creator)
|
||||
->post(route('creator.stories.publish-now', ['story' => $story->id]));
|
||||
|
||||
$response->assertRedirect(route('stories.show', ['slug' => $story->slug]));
|
||||
|
||||
$story->refresh();
|
||||
|
||||
expect($story->status)->toBe('published');
|
||||
expect($story->published_at)->not->toBeNull();
|
||||
|
||||
$this->assertDatabaseHas('activity_events', [
|
||||
'actor_id' => $creator->id,
|
||||
'type' => ActivityEvent::TYPE_UPLOAD,
|
||||
'target_type' => ActivityEvent::TARGET_STORY,
|
||||
'target_id' => $story->id,
|
||||
]);
|
||||
|
||||
$notification = $creator->fresh()
|
||||
->notifications()
|
||||
->where('type', 'story_published')
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
expect($notification)->toBeInstanceOf(Notification::class);
|
||||
expect($notification->data['type'] ?? null)->toBe('story_published');
|
||||
});
|
||||
|
||||
it('published story page renders successfully', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$story = Story::query()->create([
|
||||
'creator_id' => $creator->id,
|
||||
'title' => 'Renderable Story',
|
||||
'slug' => 'renderable-story-' . Str::lower(Str::random(6)),
|
||||
'excerpt' => 'Renderable excerpt',
|
||||
'content' => json_encode([
|
||||
'type' => 'doc',
|
||||
'content' => [
|
||||
['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Renderable story content.']]],
|
||||
['type' => 'codeBlock', 'attrs' => ['language' => 'bash'], 'content' => [['type' => 'text', 'text' => 'git clone https://github.com/klevze/sqlBackup.git']]],
|
||||
],
|
||||
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
|
||||
'story_type' => 'creator_story',
|
||||
'status' => 'published',
|
||||
'published_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
$this->get(route('stories.show', ['slug' => $story->slug]))
|
||||
->assertOk()
|
||||
->assertSee('Renderable Story', false)
|
||||
->assertSee('language-bash', false)
|
||||
->assertDontSee('{"type":"doc"', false);
|
||||
});
|
||||
|
||||
it('creator can publish through story editor api create endpoint', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($creator)
|
||||
->postJson(route('api.stories.create'), [
|
||||
'title' => 'API Publish Story',
|
||||
'story_type' => 'creator_story',
|
||||
'content' => [
|
||||
'type' => 'doc',
|
||||
'content' => [
|
||||
['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Story body for API publishing.']]],
|
||||
],
|
||||
],
|
||||
'submit_action' => 'publish_now',
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('status', 'published')
|
||||
->assertJsonPath('public_url', fn (string $url) => str_contains($url, '/stories/'));
|
||||
|
||||
$storyId = (int) $response->json('story_id');
|
||||
$story = Story::query()->findOrFail($storyId);
|
||||
|
||||
expect($story->status)->toBe('published');
|
||||
expect($story->published_at)->not->toBeNull();
|
||||
});
|
||||
|
||||
it('creator can publish through story editor api update endpoint', function () {
|
||||
$creator = User::factory()->create();
|
||||
|
||||
$story = Story::query()->create([
|
||||
'creator_id' => $creator->id,
|
||||
'title' => 'API Draft Story',
|
||||
'slug' => 'api-draft-story-' . Str::lower(Str::random(6)),
|
||||
'content' => '<p>Draft content</p>',
|
||||
'story_type' => 'creator_story',
|
||||
'status' => 'draft',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($creator)
|
||||
->putJson(route('api.stories.update'), [
|
||||
'story_id' => $story->id,
|
||||
'title' => 'API Published Story',
|
||||
'story_type' => 'creator_story',
|
||||
'content' => [
|
||||
'type' => 'doc',
|
||||
'content' => [
|
||||
['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Updated story content for publication.']]],
|
||||
],
|
||||
],
|
||||
'submit_action' => 'publish_now',
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('status', 'published')
|
||||
->assertJsonPath('preview_url', fn (string $url) => str_contains($url, '/preview'));
|
||||
|
||||
$story->refresh();
|
||||
|
||||
expect($story->title)->toBe('API Published Story');
|
||||
expect($story->status)->toBe('published');
|
||||
expect($story->published_at)->not->toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user