mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
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
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Insights;
|
|
|
|
use App\Dto\Insights\ListingHistory;
|
|
use App\Services\Insights\PriceStatsCalculator;
|
|
use Tests\TestCase;
|
|
|
|
class PriceStatsCalculatorTest extends TestCase
|
|
{
|
|
public function test_it_computes_low_high_average_current_and_store(): void
|
|
{
|
|
$series = collect([
|
|
'2026-01-01' => 60.0,
|
|
'2026-01-02' => 40.0,
|
|
'2026-01-03' => 50.0,
|
|
]);
|
|
$listings = collect([
|
|
new ListingHistory('Big W', collect(['2026-01-02' => 40.0])),
|
|
]);
|
|
|
|
$stats = (new PriceStatsCalculator)->calculate($series, $listings);
|
|
|
|
$this->assertSame(40.0, $stats->lowest);
|
|
$this->assertSame('2026-01-02', $stats->lowestDate);
|
|
$this->assertSame('Big W', $stats->lowestStore);
|
|
$this->assertSame(60.0, $stats->highest);
|
|
$this->assertSame(50.0, $stats->average);
|
|
$this->assertSame(50.0, $stats->current);
|
|
$this->assertSame(0.0, $stats->percentVsAverage);
|
|
}
|
|
|
|
public function test_empty_series_returns_zeroed_stats(): void
|
|
{
|
|
$stats = (new PriceStatsCalculator)->calculate(collect(), collect());
|
|
|
|
$this->assertSame(0.0, $stats->lowest);
|
|
$this->assertNull($stats->lowestDate);
|
|
}
|
|
}
|