Files
portal/app/tests/Feature/Models/SupplierSyncLogTest.php
T

40 lines
1.4 KiB
PHP
Raw Normal View History

<?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();
});