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.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Insights;
|
|
|
|
use App\Dto\Insights\ListingHistory;
|
|
use App\Enums\StockStatus;
|
|
use App\Services\Insights\StoreShowdownCalculator;
|
|
use Tests\TestCase;
|
|
|
|
class StoreShowdownCalculatorTest extends TestCase
|
|
{
|
|
public function test_it_ranks_by_current_price_and_computes_win_rate(): void
|
|
{
|
|
$listings = collect([
|
|
new ListingHistory('Big W', collect([
|
|
'2026-01-01' => 50.0, '2026-01-02' => 42.0,
|
|
]), StockStatus::InStock),
|
|
new ListingHistory('Amazon', collect([
|
|
'2026-01-01' => 48.0, '2026-01-02' => 47.0,
|
|
]), StockStatus::InStock),
|
|
]);
|
|
|
|
$result = (new StoreShowdownCalculator)->calculate($listings);
|
|
|
|
$this->assertSame('Big W', $result->first()->storeName);
|
|
$this->assertTrue($result->first()->isCheapestToday);
|
|
$this->assertEqualsWithDelta(0.5, $result->first()->winRate, 0.001);
|
|
}
|
|
|
|
public function test_out_of_stock_listing_marked_unavailable(): void
|
|
{
|
|
$listings = collect([
|
|
new ListingHistory('Amazon', collect(['2026-01-01' => 47.0]), StockStatus::OutOfStock),
|
|
]);
|
|
|
|
$result = (new StoreShowdownCalculator)->calculate($listings);
|
|
|
|
$this->assertFalse($result->first()->isAvailable);
|
|
}
|
|
}
|