Files
portal/app/tests/Feature/Import/ImportModelsTest.php
T
Дмитрий 8bc8c53a3b feat(import): Eloquent-модели ImportLog + ImportUnknownStatus
- ImportLog: $attributes зеркалят DB DEFAULT'ов (status/entity_type/dry_run),
  CREATED_AT/UPDATED_AT=null (таблица использует started_at/finished_at),
  casts для mapping_config (array) и dry_run (boolean)
- ImportUnknownStatus: scope unresolved() (whereNull mapped_to_slug),
  BelongsTo tenant
- Фабрики ImportLogFactory + ImportUnknownStatusFactory
- Тест ImportModelsTest (2/2, DatabaseTransactions, idempotent)
- ide-helper:models перегенерирован под новые модели
- phpstan-baseline регенерирован (квирк 25: TestCall::$tenant/$user)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 17:29:33 +03:00

53 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\ImportLog;
use App\Models\ImportUnknownStatus;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
uses(DatabaseTransactions::class);
beforeEach(function (): void {
$this->tenant = Tenant::factory()->create();
$this->user = User::factory()->for($this->tenant)->create();
DB::statement('SET app.current_tenant_id = '.$this->tenant->id);
});
test('ImportLog создаётся с дефолтами и кастует mapping_config/dry_run', function (): void {
$log = ImportLog::create([
'tenant_id' => $this->tenant->id,
'user_id' => $this->user->id,
'filename' => 'leads.csv',
'file_path' => 'imports/1/uuid.csv',
'mapping_config' => ['status' => ['Новые' => 'new']],
'dry_run' => true,
]);
expect($log->status)->toBe('pending')
->and($log->entity_type)->toBe('leads')
->and($log->dry_run)->toBeTrue()
->and($log->mapping_config)->toBe(['status' => ['Новые' => 'new']]);
});
test('ImportUnknownStatus хранит маппинг и фильтруется scope unresolved', function (): void {
ImportUnknownStatus::create([
'tenant_id' => $this->tenant->id,
'status_ru' => 'Архив',
'occurrences' => 3,
]);
ImportUnknownStatus::create([
'tenant_id' => $this->tenant->id,
'status_ru' => 'Спам',
'occurrences' => 1,
'mapped_to_slug' => 'closed',
'resolved_at' => now(),
]);
expect(ImportUnknownStatus::unresolved()->count())->toBe(1)
->and(ImportUnknownStatus::unresolved()->first()->status_ru)->toBe('Архив');
});