50 lines
2.5 KiB
PHP
50 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Models\AutopodborCompetitor;
|
||
|
|
use App\Models\AutopodborRun;
|
||
|
|
use App\Models\AutopodborSource;
|
||
|
|
use App\Models\Project;
|
||
|
|
use App\Models\Tenant;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Tests\Concerns\SharesSupplierPdo;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
|
||
|
|
|
||
|
|
it('GET /competitors/{id} — у каждого источника есть ящик и статус проекта', function () {
|
||
|
|
$tenant = Tenant::factory()->create();
|
||
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
||
|
|
DB::statement('SET app.current_tenant_id = '.$tenant->id);
|
||
|
|
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'study', 'status' => 'done', 'region_code' => 16, 'params' => []]);
|
||
|
|
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Окна', 'dedup_key' => 'okna']);
|
||
|
|
|
||
|
|
$project = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true, 'preflight_blocked_at' => null]);
|
||
|
|
|
||
|
|
// источник в работе с активным проектом
|
||
|
|
AutopodborSource::create([
|
||
|
|
'tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id,
|
||
|
|
'signal_type' => 'call', 'identifier' => '78432001122', 'phone_kind' => 'real', 'phone_type' => 'city',
|
||
|
|
'dedup_key' => 'call:78432001122', 'box' => 'field', 'created_project_id' => $project->id,
|
||
|
|
]);
|
||
|
|
// источник-предложение без проекта
|
||
|
|
AutopodborSource::create([
|
||
|
|
'tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id,
|
||
|
|
'signal_type' => 'site', 'identifier' => 'okna.ru', 'dedup_key' => 'site:okna.ru', 'box' => 'proposal',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$resp = $this->actingAs($user)->getJson("/api/autopodbor/competitors/{$comp->id}")
|
||
|
|
->assertOk()
|
||
|
|
->assertJsonStructure(['data' => ['id', 'name'], 'sources' => [['id', 'box', 'phone_type', 'project']]]);
|
||
|
|
|
||
|
|
$byId = collect($resp->json('sources'))->keyBy('identifier');
|
||
|
|
expect($byId['78432001122']['box'])->toBe('field')
|
||
|
|
->and($byId['78432001122']['phone_type'])->toBe('city')
|
||
|
|
->and($byId['78432001122']['project'])->not->toBeNull()
|
||
|
|
->and($byId['78432001122']['project']['is_active'])->toBeTrue()
|
||
|
|
->and($byId['okna.ru']['box'])->toBe('proposal')
|
||
|
|
->and($byId['okna.ru']['project'])->toBeNull();
|
||
|
|
});
|