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
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Insights;
|
|
|
|
use App\Dto\Insights\ListingHistory;
|
|
use App\Services\Insights\DropEventCalculator;
|
|
use Tests\TestCase;
|
|
|
|
class DropEventCalculatorTest extends TestCase
|
|
{
|
|
public function test_it_detects_moves_over_the_threshold_newest_first(): void
|
|
{
|
|
$listings = collect([
|
|
new ListingHistory('Big W', collect([
|
|
'2026-01-01' => 50.0,
|
|
'2026-01-02' => 50.5,
|
|
'2026-01-03' => 42.0,
|
|
'2026-01-04' => 46.0,
|
|
])),
|
|
]);
|
|
|
|
$events = (new DropEventCalculator)->calculate($listings, 3, 6);
|
|
|
|
$this->assertCount(2, $events);
|
|
$this->assertSame('2026-01-04', $events->first()->date);
|
|
$this->assertFalse($events->first()->isDrop);
|
|
$this->assertTrue($events->last()->isDrop);
|
|
$this->assertSame(-8.0, $events->last()->change);
|
|
}
|
|
|
|
public function test_limit_caps_results(): void
|
|
{
|
|
$listings = collect([
|
|
new ListingHistory('A', collect([
|
|
'2026-01-01' => 100.0, '2026-01-02' => 80.0, '2026-01-03' => 60.0,
|
|
'2026-01-04' => 40.0, '2026-01-05' => 20.0,
|
|
])),
|
|
]);
|
|
|
|
$events = (new DropEventCalculator)->calculate($listings, 3, 2);
|
|
|
|
$this->assertCount(2, $events);
|
|
}
|
|
}
|