2026-05-29 16:15:27 +03:00
|
|
|
<?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',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-09 08:54:10 +03:00
|
|
|
it('all 6 audit tables use global-within-partition chain (ADR-021, supersedes ADR-018)', function (): void {
|
|
|
|
|
// ADR-021: триггер де-факто пишет глобальную цепочку для ВСЕХ таблиц (проверено на
|
|
|
|
|
// проде 2026-07-09, включая balance_transactions). per-tenant scope ADR-018 никогда
|
|
|
|
|
// не был реализован → все partition-clause пустые (global-within-partition).
|
|
|
|
|
foreach (AuditChainConfig::TABLES as $table => $cfg) {
|
|
|
|
|
expect($cfg['partition'])->toEqual('', "table {$table} must use global chain");
|
|
|
|
|
}
|
2026-05-29 16:15:27 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|