Add feature test coverage for the core domain
Only Breeze's default auth/profile tests existed - nothing covered Workouts, Sessions, Exercises, Yoga, Favorites, Blog, or the Admin panel, which is the actual product. Adds factories for the domain models and 45 new feature tests covering the main flows plus authorization boundaries (owner-only access on workouts/sessions, admin-only access on /admin, drafts hidden from the public blog). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Admin;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PostCrudTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function admin(): User
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$admin->is_admin = true;
|
||||
$admin->save();
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function test_regular_user_cannot_access_post_admin(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('admin.posts.index'));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_admin_can_create_a_published_post(): void
|
||||
{
|
||||
$admin = $this->admin();
|
||||
|
||||
$response = $this->actingAs($admin)->post(route('admin.posts.store'), [
|
||||
'title' => 'New Training Tips',
|
||||
'excerpt' => 'Short summary',
|
||||
'body' => 'First paragraph.',
|
||||
'published' => '1',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.posts.index'));
|
||||
$this->assertDatabaseHas('posts', [
|
||||
'title' => 'New Training Tips',
|
||||
'slug' => 'new-training-tips',
|
||||
'author_id' => $admin->id,
|
||||
]);
|
||||
$post = Post::where('slug', 'new-training-tips')->firstOrFail();
|
||||
$this->assertTrue($post->is_published);
|
||||
}
|
||||
|
||||
public function test_admin_can_create_a_draft_post(): void
|
||||
{
|
||||
$this->actingAs($this->admin())->post(route('admin.posts.store'), [
|
||||
'title' => 'Unfinished Draft',
|
||||
'body' => 'Work in progress.',
|
||||
]);
|
||||
|
||||
$post = Post::where('slug', 'unfinished-draft')->firstOrFail();
|
||||
$this->assertFalse($post->is_published);
|
||||
}
|
||||
|
||||
public function test_admin_can_update_a_post(): void
|
||||
{
|
||||
$post = Post::factory()->create(['title' => 'Old Title', 'published_at' => null]);
|
||||
|
||||
$response = $this->actingAs($this->admin())->patch(route('admin.posts.update', $post), [
|
||||
'title' => 'Updated Title',
|
||||
'body' => $post->body,
|
||||
'published' => '1',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.posts.index'));
|
||||
$post->refresh();
|
||||
$this->assertEquals('Updated Title', $post->title);
|
||||
$this->assertTrue($post->is_published);
|
||||
}
|
||||
|
||||
public function test_admin_can_delete_a_post(): void
|
||||
{
|
||||
$post = Post::factory()->create();
|
||||
|
||||
$response = $this->actingAs($this->admin())->delete(route('admin.posts.destroy', $post));
|
||||
|
||||
$response->assertRedirect(route('admin.posts.index'));
|
||||
$this->assertDatabaseMissing('posts', ['id' => $post->id]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user