d9b3e8dbe1
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
2.0 KiB
PHP
50 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AutopodborRun;
|
|
use App\Models\AutopodborCompetitor;
|
|
use App\Models\Tenant;
|
|
use App\Jobs\Autopodbor\RunAutopodborResolveJob;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(DatabaseTransactions::class, \Tests\Concerns\SharesSupplierPdo::class);
|
|
|
|
it('резолв по названию: кандидаты с origin=resolve, status=done, без списания', function () {
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '100000.00']);
|
|
DB::statement("SET app.current_tenant_id = ".$tenant->id);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id,
|
|
'kind' => 'resolve',
|
|
'status' => 'queued',
|
|
'region_code' => 16,
|
|
'params' => ['name' => 'Окна Комфорт'],
|
|
]);
|
|
|
|
app()->call([new RunAutopodborResolveJob($run->id), 'handle']);
|
|
|
|
expect($run->fresh()->status)->toBe('done')
|
|
->and($run->fresh()->price_rub_charged)->toBeNull()
|
|
->and(AutopodborCompetitor::where('search_run_id', $run->id)->where('origin', 'resolve')->count())->toBeGreaterThan(0)
|
|
->and((string) $tenant->fresh()->balance_rub)->toBe('100000.00');
|
|
});
|
|
|
|
it('пустой резолв: status=empty без списания', function () {
|
|
app()->bind(\App\Services\Autopodbor\Agent\CompetitorAgent::class, \Tests\Doubles\EmptyCompetitorAgent::class);
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '100000.00']);
|
|
DB::statement("SET app.current_tenant_id = ".$tenant->id);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id,
|
|
'kind' => 'resolve',
|
|
'status' => 'queued',
|
|
'region_code' => 16,
|
|
'params' => ['name' => 'Несуществующая Фирма XYZ'],
|
|
]);
|
|
|
|
app()->call([new RunAutopodborResolveJob($run->id), 'handle']);
|
|
|
|
expect($run->fresh()->status)->toBe('empty')
|
|
->and($run->fresh()->price_rub_charged)->toBeNull();
|
|
});
|