64 lines
3.1 KiB
PHP
64 lines
3.1 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
declare(strict_types=1);
|
|||
|
|
|
|||
|
|
use App\Http\Resources\Autopodbor\SourceResource;
|
|||
|
|
use App\Jobs\Autopodbor\RunAutopodborStudyJob;
|
|||
|
|
use App\Models\AutopodborCompetitor;
|
|||
|
|
use App\Models\AutopodborRun;
|
|||
|
|
use App\Models\AutopodborSource;
|
|||
|
|
use App\Models\SystemSetting;
|
|||
|
|
use App\Models\Tenant;
|
|||
|
|
use App\Services\Autopodbor\Agent\CompetitorAgent;
|
|||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Tests\Concerns\SharesSupplierPdo;
|
|||
|
|
use Tests\Doubles\RichCompetitorAgent;
|
|||
|
|
|
|||
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
|||
|
|
|
|||
|
|
it('изучение сохраняет «где нашли», офис и подтверждения в БД', function () {
|
|||
|
|
app()->bind(CompetitorAgent::class, RichCompetitorAgent::class);
|
|||
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '100000.00']);
|
|||
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
|||
|
|
SystemSetting::updateOrCreate(['key' => 'autopodbor_price_study_rub'], ['value' => '900', 'type' => 'decimal']);
|
|||
|
|
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'КрасЛомбард', 'dedup_key' => 'site:k.ru', 'site_url' => 'k.ru']);
|
|||
|
|
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'queued', 'region_code' => 24, 'competitor_id' => $comp->id, 'params' => []]);
|
|||
|
|
|
|||
|
|
app()->call([new RunAutopodborStudyJob($run->id), 'handle']);
|
|||
|
|
|
|||
|
|
$src = AutopodborSource::where('competitor_id', $comp->id)->where('signal_type', 'call')->firstOrFail();
|
|||
|
|
expect($src->where_found)->toBeArray()->toHaveCount(2);
|
|||
|
|
expect(collect($src->where_found)->pluck('url'))->toContain('https://2gis.ru/firm/1');
|
|||
|
|
expect($src->office)->toBe('Единая справочная');
|
|||
|
|
expect($src->confirmations)->toBe(2);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('API-ресурс источника отдаёт where_found, office и confirmations', function () {
|
|||
|
|
$tenant = Tenant::factory()->create();
|
|||
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
|||
|
|
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'К', 'dedup_key' => 'site:k.ru', 'site_url' => 'k.ru']);
|
|||
|
|
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'done', 'region_code' => 24, 'competitor_id' => $comp->id, 'params' => []]);
|
|||
|
|
$src = AutopodborSource::create([
|
|||
|
|
'tenant_id' => $tenant->id,
|
|||
|
|
'competitor_id' => $comp->id,
|
|||
|
|
'study_run_id' => $run->id,
|
|||
|
|
'signal_type' => 'call',
|
|||
|
|
'identifier' => '73912920000',
|
|||
|
|
'phone_kind' => 'real',
|
|||
|
|
'phone_type' => 'city',
|
|||
|
|
'provenance_url' => 'https://k.ru',
|
|||
|
|
'provenance_label' => 'в коде сайта',
|
|||
|
|
'dedup_key' => 'call:73912920000',
|
|||
|
|
'where_found' => [['label' => 'в коде сайта', 'url' => 'https://k.ru'], ['label' => '2ГИС', 'url' => 'https://2gis.ru/firm/1']],
|
|||
|
|
'office' => 'Единая справочная',
|
|||
|
|
'confirmations' => 2,
|
|||
|
|
]);
|
|||
|
|
|
|||
|
|
$arr = (new SourceResource($src))->toArray(request());
|
|||
|
|
|
|||
|
|
expect($arr['where_found'])->toHaveCount(2);
|
|||
|
|
expect($arr['office'])->toBe('Единая справочная');
|
|||
|
|
expect($arr['confirmations'])->toBe(2);
|
|||
|
|
});
|