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
37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Insights;
|
|
|
|
use App\Dto\Insights\ListingHistory;
|
|
use App\Enums\StockStatus;
|
|
use App\Services\Insights\AvailabilityCalculator;
|
|
use Tests\TestCase;
|
|
|
|
class AvailabilityCalculatorTest extends TestCase
|
|
{
|
|
public function test_it_builds_segments_and_in_stock_percent_from_gaps(): void
|
|
{
|
|
$listings = collect([
|
|
new ListingHistory('Big W', collect([
|
|
'2026-01-01' => 50.0,
|
|
'2026-01-02' => 49.0,
|
|
'2026-01-04' => 48.0,
|
|
]), StockStatus::InStock),
|
|
]);
|
|
|
|
$result = (new AvailabilityCalculator)->calculate($listings);
|
|
|
|
$first = $result->first();
|
|
$this->assertSame(75.0, $first->inStockPercent);
|
|
$this->assertSame(
|
|
[
|
|
['available' => true, 'days' => 2],
|
|
['available' => false, 'days' => 1],
|
|
['available' => true, 'days' => 1],
|
|
],
|
|
$first->segments,
|
|
);
|
|
$this->assertSame(StockStatus::InStock, $first->currentStatus);
|
|
}
|
|
}
|