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')); } }