1b3683c6b1
- адресные сообщения в окнах сбора/изучения (маппер autopodborErrorMessage) - регион по умолчанию = пустой плейсхолдер «выберите регион» - кнопка «Собрать источники» у изучённого конкурента → «Источники собраны» - сквозной дедуп предложений между прогонами (без двойного списания, ретрай цел) - убран захардкоженный admin_user_id с фронта (id ставит бэкенд) - идемпотентный гард в 3 миграции автоподбора (migrate:fresh снова зелёный) - заглушка Агента: +тип 8-800 (tollfree) для полноты эмуляции Тесты: Pest автоподбор 82/82, Vitest 62/62, vite build зелёный. эскейп: фиксируй (авторизовано владельцем) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
88 lines
4.0 KiB
PHP
88 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AutopodborRun;
|
|
use App\Models\AutopodborCompetitor;
|
|
use App\Models\Tenant;
|
|
use App\Models\SystemSetting;
|
|
use App\Jobs\Autopodbor\RunAutopodborSearchJob;
|
|
use App\Services\Autopodbor\Agent\CompetitorAgent;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(DatabaseTransactions::class, \Tests\Concerns\SharesSupplierPdo::class);
|
|
|
|
function runSearchJob(int $runId): void
|
|
{
|
|
// handle через контейнер (DI зависимостей)
|
|
app()->call([new RunAutopodborSearchJob($runId), 'handle']);
|
|
}
|
|
|
|
it('успешный подбор: сохраняет конкурентов, списывает, status=done', function () {
|
|
$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']);
|
|
SystemSetting::updateOrCreate(['key' => 'autopodbor_max_competitors'], ['value' => '15', 'type' => 'int']);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id,
|
|
'kind' => 'search',
|
|
'status' => 'queued',
|
|
'region_code' => 16,
|
|
'params' => ['examples' => ['okna.ru'], 'about_self' => [], 'include_federal' => true],
|
|
]);
|
|
|
|
runSearchJob($run->id);
|
|
|
|
expect($run->fresh()->status)->toBe('done')
|
|
->and($run->fresh()->price_rub_charged)->toBe('500.00')
|
|
->and(AutopodborCompetitor::where('search_run_id', $run->id)->count())->toBeGreaterThan(0)
|
|
->and((string) $tenant->fresh()->balance_rub)->toBe('99500.00');
|
|
});
|
|
|
|
it('пустой результат: status=empty, без списания', function () {
|
|
app()->bind(CompetitorAgent::class, \Tests\Doubles\EmptyCompetitorAgent::class);
|
|
$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']);
|
|
$run = AutopodborRun::create([
|
|
'tenant_id' => $tenant->id,
|
|
'kind' => 'search',
|
|
'status' => 'queued',
|
|
'region_code' => 16,
|
|
'params' => ['examples' => [], 'about_self' => [], 'include_federal' => false],
|
|
]);
|
|
|
|
runSearchJob($run->id);
|
|
|
|
expect($run->fresh()->status)->toBe('empty')
|
|
->and($run->fresh()->price_rub_charged)->toBeNull()
|
|
->and((string) $tenant->fresh()->balance_rub)->toBe('100000.00');
|
|
});
|
|
|
|
it('повторный подбор не дублирует известных конкурентов и не списывает (сквозной дедуп)', function () {
|
|
$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' => '300', 'type' => 'decimal']);
|
|
SystemSetting::updateOrCreate(['key' => 'autopodbor_max_competitors'], ['value' => '15', 'type' => 'int']);
|
|
|
|
$mk = fn () => AutopodborRun::create([
|
|
'tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'queued',
|
|
'region_code' => 16, 'params' => ['examples' => ['okna.ru'], 'about_self' => [], 'include_federal' => true],
|
|
]);
|
|
|
|
$run1 = $mk();
|
|
runSearchJob($run1->id);
|
|
$afterFirst = AutopodborCompetitor::where('tenant_id', $tenant->id)->count();
|
|
expect($afterFirst)->toBeGreaterThan(0);
|
|
|
|
$run2 = $mk();
|
|
runSearchJob($run2->id);
|
|
|
|
// Заглушка отдаёт тот же набор → второй прогон не добавляет дублей и не списывает
|
|
expect(AutopodborCompetitor::where('tenant_id', $tenant->id)->count())->toBe($afterFirst)
|
|
->and($run2->fresh()->status)->toBe('empty')
|
|
->and($run2->fresh()->price_rub_charged)->toBeNull()
|
|
->and((string) $tenant->fresh()->balance_rub)->toBe('99700.00');
|
|
});
|