Files
portal/app/tests/Feature/Models/SupplierSyncLogTest.php
T
Дмитрий 084a952bfa feat(models): add SupplierSyncLog model + factory (audit trail для AJAX-sync)
- app/Models/SupplierSyncLog.php — fillable + casts (jsonb arrays + datetime)
  + supplierProject() BelongsTo relation (nullable, ON DELETE SET NULL —
    лог переживает удаление supplier-проекта для audit-trail).
  $timestamps = false (только created_at, без updated_at — append-only)
- database/factories/SupplierSyncLogFactory.php — реалистичные действия из enum
- tests/Feature/Models/SupplierSyncLogTest.php — 4 теста: factory,
  supplier_project relation, jsonb array casts, nullable FK lifecycle

Pest: 463 / 461 passed / 2 skipped (457 + 4 новых = 461).
Larastan: 0 errors. Pint passed.

Spec: §4.3
Plan: Task 9

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

40 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\SupplierProject;
use App\Models\SupplierSyncLog;
use Illuminate\Foundation\Testing\DatabaseTransactions;
uses(DatabaseTransactions::class);
test('SupplierSyncLog created via factory', function () {
$log = SupplierSyncLog::factory()->create();
expect($log->action)->toBeIn(['create', 'update', 'delete', 'disable', 'session_refresh']);
});
test('SupplierSyncLog has nullable supplier_project relation', function () {
$sp = SupplierProject::factory()->create();
$log = SupplierSyncLog::factory()->create(['supplier_project_id' => $sp->id]);
expect($log->supplierProject)->toBeInstanceOf(SupplierProject::class);
expect($log->supplierProject->id)->toBe($sp->id);
});
test('SupplierSyncLog request_payload and response_body cast as array', function () {
$log = SupplierSyncLog::factory()->create([
'request_payload' => ['name' => 'X'],
'response_body' => ['status' => 'OK'],
]);
expect($log->fresh()->request_payload)->toBe(['name' => 'X']);
expect($log->fresh()->response_body)->toBe(['status' => 'OK']);
});
test('SupplierSyncLog supplier_project_id can be null (lifecycle: лог переживает удаление supplier-проекта)', function () {
$log = SupplierSyncLog::factory()->create(['supplier_project_id' => null]);
expect($log->supplier_project_id)->toBeNull();
expect($log->supplierProject)->toBeNull();
});