first commit

This commit is contained in:
2026-02-04 23:23:42 +07:00
commit ee28ea1a2d
202 changed files with 34797 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
<?php
namespace Tests\Feature;
use App\Models\Article;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ArticleControllerTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
}
public function test_index_returns_articles_list()
{
Article::factory()->count(3)->create();
$response = $this
->actingAs($this->user)
->getJson(route('articles.index'));
$response->assertOk()
->assertJsonStructure([
'data' => [
['id', 'title', 'content_short', 'created_at', 'comments_count']
]
]);
$this->assertCount(3, $response->json('data'));
}
public function test_store_creates_article()
{
$payload = [
'title' => 'Test Article',
'content' => 'Some content for test',
];
$response = $this
->actingAs($this->user)
->postJson(route('articles.store'), $payload);
$response->assertCreated()
->assertJsonFragment([
'title' => 'Test Article',
'content_short' => 'Some content for test',
]);
$this->assertDatabaseHas('articles', [
'title' => 'Test Article',
'content' => 'Some content for test',
]);
}
public function test_show_returns_article_detail()
{
$article = Article::factory()->create();
$response = $this
->actingAs($this->user)
->getJson(route('articles.show', $article));
$response->assertOk()
->assertJsonStructure([
'data' => [
'id',
'title',
'content',
'created_at',
'comments',
]
]);
$this->assertEquals($article->id, $response->json('data.id'));
}
}