Files
pricebuddy/tests/Unit/Services/Insights/SeasonalityCalculatorTest.php
Jeremy d1a8f1d009 feat: product insights tab
Add a Product Insights tab backed by a suite of price-analysis calculators and a
redesigned price history chart.

- Insights calculators: listing-history and daily best-price series builders,
  price stats, percentile, deal score, distribution, drop events, store showdown,
  seasonality, availability timeline, and target tracker
- ProductInsights aggregator service composing the calculators
- Price history chart: best-price and target datasets, best-price line honours the
  unit/retail filter, horizontal scroll on mobile
- Rename the History tab to Insights with consistent heading styling
- Feature and unit test coverage, plus review-feedback fixes
2026-06-18 23:13:14 +10:00

35 lines
973 B
PHP

<?php
namespace Tests\Unit\Services\Insights;
use App\Services\Insights\SeasonalityCalculator;
use Tests\TestCase;
class SeasonalityCalculatorTest extends TestCase
{
public function test_it_averages_by_month_and_picks_cheapest(): void
{
$series = collect([
'2025-06-01' => 30.0,
'2025-06-15' => 40.0,
'2025-08-01' => 80.0,
]);
$result = (new SeasonalityCalculator)->calculate($series);
$this->assertSame(35.0, $result->monthlyAverages[6]);
$this->assertSame(80.0, $result->monthlyAverages[8]);
$this->assertNull($result->monthlyAverages[1]);
$this->assertSame([6], $result->cheapestMonths);
}
public function test_short_history_has_not_enough_data(): void
{
$result = (new SeasonalityCalculator)->calculate(collect([
'2026-01-01' => 30.0, '2026-01-10' => 31.0,
]));
$this->assertFalse($result->hasEnoughData);
}
}