getJson('/api/v1/dashboard/stats'); $response->assertStatus(200) ->assertJsonStructure([ 'success', 'data' => [ 'article_stats' => [ 'articles_fetched', 'articles_published', 'published_percentage', ], 'system_stats' => [ 'total_feeds', 'active_feeds', 'total_channels', 'active_channels', 'total_routes', 'active_routes', ], 'available_periods', 'current_period', ], 'message' ]); } public function test_stats_with_different_periods(): void { $periods = ['today', 'week', 'month', 'year', 'all']; foreach ($periods as $period) { $response = $this->getJson("/api/v1/dashboard/stats?period={$period}"); $response->assertStatus(200) ->assertJson([ 'success' => true, 'data' => [ 'current_period' => $period, ] ]); } } public function test_stats_with_sample_data(): void { // Get initial counts $initialArticles = Article::count(); $initialFeeds = Feed::count(); $initialChannels = PlatformChannel::count(); $initialRoutes = Route::count(); $initialPublications = ArticlePublication::count(); // Create test data $feed = Feed::factory()->create(['is_active' => true]); $channel = PlatformChannel::factory()->create(['is_active' => true]); $route = Route::factory()->create(['is_active' => true]); // Create articles $articles = Article::factory()->count(3)->create(['feed_id' => $feed->id]); // Publish one article ArticlePublication::factory()->create([ 'article_id' => $articles->first()->id, 'platform_channel_id' => $channel->id, 'published_at' => now() ]); $response = $this->getJson('/api/v1/dashboard/stats?period=all'); $response->assertStatus(200) ->assertJson([ 'success' => true, 'data' => [ 'article_stats' => [ 'articles_fetched' => $initialArticles + 3, 'articles_published' => $initialPublications + 1, ], ] ]); // Just verify structure and that we have more items than we started with $responseData = $response->json('data'); $this->assertGreaterThanOrEqual($initialFeeds + 1, $responseData['system_stats']['total_feeds']); $this->assertGreaterThanOrEqual($initialChannels + 1, $responseData['system_stats']['total_channels']); $this->assertGreaterThanOrEqual($initialRoutes + 1, $responseData['system_stats']['total_routes']); } public function test_stats_returns_empty_data_with_no_records(): void { $response = $this->getJson('/api/v1/dashboard/stats'); $response->assertStatus(200) ->assertJson([ 'success' => true, 'data' => [ 'article_stats' => [ 'articles_fetched' => 0, 'articles_published' => 0, 'published_percentage' => 0.0, ], 'system_stats' => [ 'total_feeds' => 0, 'active_feeds' => 0, 'total_channels' => 0, 'active_channels' => 0, 'total_routes' => 0, 'active_routes' => 0, ], ] ]); } }