create(['balance_rub' => '100000.00']); DB::statement("SET app.current_tenant_id = ".$tenant->id); SystemSetting::updateOrCreate(['key' => 'autopodbor_price_search_rub'], ['value' => '500', 'type' => 'decimal']); $run = app(AutopodborRunService::class)->startSearch($tenant->id, 16, ['okna.ru'], [], true); expect($run->kind)->toBe('search')->and($run->status)->toBe('queued'); Queue::assertPushed(RunAutopodborSearchJob::class); }); it('не стартует второй in-flight search того же tenant', function () { Queue::fake(); $tenant = Tenant::factory()->create(['balance_rub' => '100000.00']); DB::statement("SET app.current_tenant_id = ".$tenant->id); SystemSetting::updateOrCreate(['key' => 'autopodbor_price_search_rub'], ['value' => '500', 'type' => 'decimal']); $svc = app(AutopodborRunService::class); $svc->startSearch($tenant->id, 16, ['okna.ru'], [], true); expect(fn () => $svc->startSearch($tenant->id, 16, ['okna.ru'], [], true)) ->toThrow(\App\Exceptions\Autopodbor\RunInFlightException::class); }); it('гейтит по балансу: нехватка на цену search → InsufficientBalanceException', function () { Queue::fake(); $tenant = Tenant::factory()->create(['balance_rub' => '100.00']); DB::statement("SET app.current_tenant_id = ".$tenant->id); SystemSetting::updateOrCreate(['key' => 'autopodbor_price_search_rub'], ['value' => '500', 'type' => 'decimal']); expect(fn () => app(AutopodborRunService::class)->startSearch($tenant->id, 16, ['okna.ru'], [], true)) ->toThrow(\App\Exceptions\Billing\InsufficientBalanceException::class); Queue::assertNotPushed(RunAutopodborSearchJob::class); }); it('startResolve бесплатный: стартует даже при нулевом балансе, ставит resolve-джобу', function () { Queue::fake(); $tenant = Tenant::factory()->create(['balance_rub' => '0.00']); DB::statement("SET app.current_tenant_id = ".$tenant->id); $run = app(AutopodborRunService::class)->startResolve($tenant->id, 'Окна Комфорт', 16); expect($run->kind)->toBe('resolve')->and($run->status)->toBe('queued'); Queue::assertPushed(RunAutopodborResolveJob::class); });