Files
portal/app/tests/Unit/Services/Audit/AuditChainConfigTest.php
T

39 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\Audit\AuditChainConfig;
it('exposes all 6 audit tables', function (): void {
expect(array_keys(AuditChainConfig::TABLES))->toEqual([
'auth_log',
'activity_log',
'tenant_operations_log',
'balance_transactions',
'pd_processing_log',
'saas_admin_audit_log',
]);
});
it('activity_log uses PARTITION BY tenant_id', function (): void {
expect(AuditChainConfig::TABLES['activity_log']['partition'])
->toEqual('PARTITION BY tenant_id');
});
it('auth_log and saas_admin_audit_log use global chain (empty partition)', function (): void {
expect(AuditChainConfig::TABLES['auth_log']['partition'])->toEqual('');
expect(AuditChainConfig::TABLES['saas_admin_audit_log']['partition'])->toEqual('');
});
it('rowExpression builds ROW(...) with NULL::bytea at __log_hash__ position', function (): void {
$expr = AuditChainConfig::rowExpression('activity_log');
expect($expr)->toEqual(
'ROW(t.id, t.tenant_id, t.user_id, t.deal_id, t.event, t.old_value, '
.'t.new_value, t.context, t.ip_address, t.user_agent, NULL::bytea, t.created_at)'
);
});
it('rowExpression throws on unknown table', function (): void {
AuditChainConfig::rowExpression('unknown_table');
})->throws(InvalidArgumentException::class);