Files
pricebuddy/tests/Feature/Filament/StoreMissingPriceToggleTest.php
Jeremy Graham 57f7369647 feat: store option to treat a missing price as out of stock
Some stores (e.g. Amazon) remove the price element when a product is
out of stock. A missing price was a scrape error, so the product could
not be created, and AI self-healing could move the price selector onto
an unrelated price on the page.

Add a per-store 'Treat a missing price as out of stock' setting. When
it is on, ScrapeUrl::resolveStockStatus() reads a page with a title but
no price as OutOfStock, so creation succeeds and healing does not run.

Fixes #222
2026-10-01 20:51:10 +10:00

48 lines
1.4 KiB
PHP

<?php
namespace Tests\Feature\Filament;
use App\Filament\Resources\StoreResource\Pages\EditStore;
use App\Models\Store;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class StoreMissingPriceToggleTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->actingAs(User::factory()->create(['email' => 'test@test.com']));
}
public function test_toggle_is_rendered(): void
{
$store = Store::factory()->create(['settings' => ['scraper_service' => 'http']]);
Livewire::test(EditStore::class, ['record' => $store->getKey()])
->assertSee('Treat a missing price as out of stock');
}
public function test_toggle_persists(): void
{
$store = Store::factory()->create(['settings' => ['scraper_service' => 'http']]);
Livewire::test(EditStore::class, ['record' => $store->getKey()])
->set('data.domains', null)
->fillForm([
'domains' => [['domain' => 'example.com']],
'settings.locale_settings.locale' => 'en_US',
'settings.locale_settings.currency' => 'USD',
'settings.missing_price_out_of_stock' => true,
])
->call('save')
->assertHasNoFormErrors();
$this->assertTrue($store->fresh()->missing_price_out_of_stock);
}
}