diff --git a/app/app/Models/AutopodborCompetitor.php b/app/app/Models/AutopodborCompetitor.php new file mode 100644 index 00000000..bc0488c0 --- /dev/null +++ b/app/app/Models/AutopodborCompetitor.php @@ -0,0 +1,53 @@ + 'bool', + 'directory_urls' => 'array', + 'provenance' => 'array', + 'studied_at' => 'datetime', + 'created_at' => 'datetime', + ]; + + public function sources(): HasMany + { + return $this->hasMany(AutopodborSource::class, 'competitor_id'); + } + + public function searchRun(): BelongsTo + { + return $this->belongsTo(AutopodborRun::class, 'search_run_id'); + } + + public function studyRun(): BelongsTo + { + return $this->belongsTo(AutopodborRun::class, 'study_run_id'); + } +} diff --git a/app/app/Models/AutopodborRun.php b/app/app/Models/AutopodborRun.php new file mode 100644 index 00000000..48f159a8 --- /dev/null +++ b/app/app/Models/AutopodborRun.php @@ -0,0 +1,40 @@ + 'array', + 'price_rub_charged' => 'decimal:2', + 'started_at' => 'datetime', + 'finished_at' => 'datetime', + 'created_at' => 'datetime', + ]; + + public function competitors(): HasMany + { + return $this->hasMany(AutopodborCompetitor::class, 'search_run_id'); + } +} diff --git a/app/app/Models/AutopodborSource.php b/app/app/Models/AutopodborSource.php new file mode 100644 index 00000000..2aedfddb --- /dev/null +++ b/app/app/Models/AutopodborSource.php @@ -0,0 +1,40 @@ + 'datetime', + ]; + + public function competitor(): BelongsTo + { + return $this->belongsTo(AutopodborCompetitor::class, 'competitor_id'); + } + + public function project(): BelongsTo + { + return $this->belongsTo(Project::class, 'created_project_id'); + } +} diff --git a/app/tests/Feature/Autopodbor/AutopodborModelsTest.php b/app/tests/Feature/Autopodbor/AutopodborModelsTest.php new file mode 100644 index 00000000..474bf3cc --- /dev/null +++ b/app/tests/Feature/Autopodbor/AutopodborModelsTest.php @@ -0,0 +1,45 @@ +create(); + DB::statement("SET LOCAL app.current_tenant_id = " . $tenant->id); + + $run = AutopodborRun::create([ + 'tenant_id' => $tenant->id, + 'kind' => 'search', + 'status' => 'done', + 'region_code' => 16, + 'params' => [], + ]); + + $comp = AutopodborCompetitor::create([ + 'tenant_id' => $tenant->id, + 'search_run_id' => $run->id, + 'name' => 'Окна Комфорт', + 'dedup_key' => 'okna-komfort', + 'relevance_pct' => 100, + ]); + + $src = AutopodborSource::create([ + 'tenant_id' => $tenant->id, + 'competitor_id' => $comp->id, + 'study_run_id' => $run->id, + 'signal_type' => 'site', + 'identifier' => 'okna-komfort.ru', + 'dedup_key' => 'site:okna-komfort.ru', + ]); + + expect($comp->sources()->count())->toBe(1) + ->and($comp->searchRun->id)->toBe($run->id) + ->and($src->competitor->id)->toBe($comp->id) + ->and($run->competitors()->count())->toBe(1); +});