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
28 lines
935 B
PHP
28 lines
935 B
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Insights;
|
|
|
|
use App\Models\Product;
|
|
use App\Services\Insights\ListingHistoriesBuilder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ListingHistoriesBuilderTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_it_builds_one_listing_per_url_with_store_name_and_history(): void
|
|
{
|
|
$product = Product::factory()
|
|
->addUrlWithPrices('https://example-a.com/p', [50, 45, 42])
|
|
->addUrlWithPrices('https://example-b.com/p', [60, 55])
|
|
->create();
|
|
|
|
$listings = (new ListingHistoriesBuilder)->build($product);
|
|
|
|
$this->assertCount(2, $listings);
|
|
$this->assertSame(3, $listings->firstWhere('storeName', $product->urls[0]->store->name)->history->count());
|
|
$this->assertSame(42.0, (float) $listings->firstWhere('storeName', $product->urls[0]->store->name)->history->last());
|
|
}
|
|
}
|