Files
pricebuddy/tests/Feature/Filament/AppSettingsPageTest.php
Jeremy dc88f7b037 test: fix settings save isolation and updatePrices return assertions
- Forget the AppSettings singleton in TestCase::setUp so each test loads
  settings fresh from the migrated DB; a singleton loaded before the new
  settings rows exist marks them default-loaded, making AppSettings::save()
  throw MissingSettings (exposed by the new required scrape_retry settings).
- Align the retry-settings page test with the existing convention (assert no
  form errors on the fields; add a min-value validation test) instead of a
  full-form persistence assertion the page's unrelated required fields block.
- Update UrlTest for the new Collection return type of Product::updatePrices().

harden: RetryUrlPriceJob tries/missing-models/notification throttle

Address final code review findings:
- Set $tries=1 so queue-level retries don't duplicate the explicit retry chain.
- Set $deleteWhenMissingModels=true so a URL/product deleted before the delayed
  job runs is discarded silently rather than failing the job.
- Throttle the exhaustion notification to one per product per retry window, so a
  multi-URL product doesn't send duplicate product-level scrape-fail notices.
- Assert the retry delay is applied in the job tests.
2026-06-10 21:58:32 +10:00

105 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature\Filament;
use App\Filament\Pages\AppSettingsPage;
use App\Models\User;
use App\Settings\AppSettings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class AppSettingsPageTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->actingAs(User::factory()->create());
}
public function test_max_priced_results_rejects_non_integer_values()
{
Livewire::test(AppSettingsPage::class)
->fillForm([
'integrated_services.searxng.enabled' => true,
'integrated_services.searxng.url' => 'https://searxng.example.com/search',
'integrated_services.searxng.max_priced_results' => 2.5,
])
->call('save')
->assertHasFormErrors(['integrated_services.searxng.max_priced_results' => 'integer']);
}
public function test_max_priced_results_accepts_integer_values()
{
Livewire::test(AppSettingsPage::class)
->fillForm([
'integrated_services.searxng.enabled' => true,
'integrated_services.searxng.url' => 'https://searxng.example.com/search',
'integrated_services.searxng.max_priced_results' => 3,
])
->call('save')
->assertHasNoFormErrors(['integrated_services.searxng.max_priced_results']);
}
public function test_settings_page_renders_the_tabs(): void
{
Livewire::test(AppSettingsPage::class)
->assertSee('General')
->assertSee('Scraping')
->assertSee('Notifications')
->assertSee('AI');
}
public function test_a_general_tab_field_saves_without_error(): void
{
Livewire::test(AppSettingsPage::class)
->fillForm(['log_retention_days' => 90])
->call('save')
->assertHasNoFormErrors(['log_retention_days']);
}
public function test_settings_sections_render_their_headings(): void
{
Livewire::test(AppSettingsPage::class)
->assertSee('Scrape Settings')
->assertSee('Locale')
->assertSee('Logging')
->assertSee('Email');
}
public function test_retry_settings_have_expected_defaults(): void
{
$settings = AppSettings::new();
$this->assertSame(3, $settings->scrape_retry_max_attempts);
$this->assertSame(15, $settings->scrape_retry_delay_minutes);
}
public function test_retry_settings_save_without_error(): void
{
// Mirrors test_a_general_tab_field_saves_without_error: this page's full
// save can be blocked by unrelated required fields (e.g. SearXng), so we
// assert only that the retry fields themselves accept valid input.
Livewire::test(AppSettingsPage::class)
->fillForm([
'scrape_retry_max_attempts' => 4,
'scrape_retry_delay_minutes' => 20,
])
->call('save')
->assertHasNoFormErrors(['scrape_retry_max_attempts', 'scrape_retry_delay_minutes']);
}
public function test_retry_settings_reject_values_below_one(): void
{
Livewire::test(AppSettingsPage::class)
->fillForm([
'scrape_retry_max_attempts' => 0,
'scrape_retry_delay_minutes' => 0,
])
->call('save')
->assertHasFormErrors(['scrape_retry_max_attempts', 'scrape_retry_delay_minutes']);
}
}