Files
pricebuddy/tests/Feature/Models/ProductUpdatePricesTest.php
Jeremy 18ad621edc feat: updatePrices returns failed urls instead of bool
feat: add scrape retry settings (max attempts, delay)

chore: clarify retry setting docs, fix test import, and make migration idempotent

- Add PHPDoc block to AppSettings clarifying scrape_retry_* vs max_attempts_to_scrape
- Use App\Settings\AppSettings import in test instead of FQCN
- Guard settings migration with existence checks to prevent SettingAlreadyExists
  in test environments where migrate:fresh does not fully clear the settings table

feat: add retry settings inputs to app settings page
2026-06-10 21:58:31 +10:00

50 lines
1.6 KiB
PHP

<?php
namespace Tests\Feature\Models;
use App\Models\Price;
use App\Models\Product;
use App\Models\Url;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use Tests\TestCase;
class ProductUpdatePricesTest extends TestCase
{
use RefreshDatabase;
public function test_returns_empty_collection_when_all_urls_succeed(): void
{
$url = Mockery::mock(Url::class)->makePartial();
$url->shouldReceive('updatePrice')->once()->andReturn(new Price);
$product = Mockery::mock(Product::class)->makePartial();
$product->shouldReceive('updatePriceCache')->once();
$product->setRelation('urls', new EloquentCollection([$url]));
$failed = $product->updatePrices();
$this->assertInstanceOf(EloquentCollection::class, $failed);
$this->assertTrue($failed->isEmpty());
}
public function test_returns_only_the_failed_urls(): void
{
$okUrl = Mockery::mock(Url::class)->makePartial();
$okUrl->shouldReceive('updatePrice')->once()->andReturn(new Price);
$failUrl = Mockery::mock(Url::class)->makePartial();
$failUrl->shouldReceive('updatePrice')->once()->andReturnNull();
$product = Mockery::mock(Product::class)->makePartial();
$product->shouldReceive('updatePriceCache')->once();
$product->setRelation('urls', new EloquentCollection([$okUrl, $failUrl]));
$failed = $product->updatePrices();
$this->assertCount(1, $failed);
$this->assertSame($failUrl, $failed->first());
}
}