2026-06-28 14:16:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-07-01 15:45:37 +03:00
|
|
|
use App\Jobs\Autopodbor\RunAutopodborResolveJob;
|
2026-06-28 14:16:14 +03:00
|
|
|
use App\Models\AutopodborCompetitor;
|
2026-07-01 15:45:37 +03:00
|
|
|
use App\Models\AutopodborRun;
|
2026-06-28 14:16:14 +03:00
|
|
|
use App\Models\Tenant;
|
2026-07-01 15:45:37 +03:00
|
|
|
use App\Services\Autopodbor\Agent\CompetitorAgent;
|
2026-06-28 14:16:14 +03:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2026-07-01 15:45:37 +03:00
|
|
|
use Tests\Concerns\SharesSupplierPdo;
|
|
|
|
|
use Tests\Doubles\EmptyCompetitorAgent;
|
2026-06-28 14:16:14 +03:00
|
|
|
|
2026-07-01 15:45:37 +03:00
|
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
2026-06-28 14:16:14 +03:00
|
|
|
|
|
|
|
|
it('резолв по названию: кандидаты с origin=resolve, status=done, без списания', function () {
|
|
|
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '100000.00']);
|
2026-07-01 15:45:37 +03:00
|
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
2026-06-28 14:16:14 +03:00
|
|
|
$run = AutopodborRun::create([
|
2026-07-01 15:45:37 +03:00
|
|
|
'tenant_id' => $tenant->id,
|
|
|
|
|
'kind' => 'resolve',
|
|
|
|
|
'status' => 'queued',
|
2026-06-28 14:16:14 +03:00
|
|
|
'region_code' => 16,
|
2026-07-01 15:45:37 +03:00
|
|
|
'params' => ['name' => 'Окна Комфорт'],
|
2026-06-28 14:16:14 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
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 () {
|
2026-07-01 15:45:37 +03:00
|
|
|
app()->bind(CompetitorAgent::class, EmptyCompetitorAgent::class);
|
2026-06-28 14:16:14 +03:00
|
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '100000.00']);
|
2026-07-01 15:45:37 +03:00
|
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
2026-06-28 14:16:14 +03:00
|
|
|
$run = AutopodborRun::create([
|
2026-07-01 15:45:37 +03:00
|
|
|
'tenant_id' => $tenant->id,
|
|
|
|
|
'kind' => 'resolve',
|
|
|
|
|
'status' => 'queued',
|
2026-06-28 14:16:14 +03:00
|
|
|
'region_code' => 16,
|
2026-07-01 15:45:37 +03:00
|
|
|
'params' => ['name' => 'Несуществующая Фирма XYZ'],
|
2026-06-28 14:16:14 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
app()->call([new RunAutopodborResolveJob($run->id), 'handle']);
|
|
|
|
|
|
|
|
|
|
expect($run->fresh()->status)->toBe('empty')
|
|
|
|
|
->and($run->fresh()->price_rub_charged)->toBeNull();
|
|
|
|
|
});
|