@@ -101,6 +101,57 @@ test('private audit preserves ordinary data while excluding bank coordinates cre
|
||||
expect($event)->toHaveKey('after_projected')->not->toHaveKey('after');
|
||||
});
|
||||
|
||||
test('purchasing audit includes supplier follow up events without bank events or foreign company history', function () {
|
||||
$included = ['supplier.created', 'supplier.updated', 'supplier.reviewed', 'supplier.document_uploaded', 'supplier.document_downloaded',
|
||||
'supplier_evaluation.approved', 'supplier_improvement.closed', 'supplier_response.decided'];
|
||||
$excluded = ['supplier.bank_viewed', 'supplier.bank_proposed', 'supplier.bank_approved', 'supplier.bank_rejected', 'supplier.future_private_action'];
|
||||
$foreign = Tenant::query()->create(['name' => 'FOREIGN-SUPPLIER-AUDIT']);
|
||||
$foreignActor = User::factory()->create(['tenant_id' => $foreign->id]);
|
||||
foreach ([...$included, ...$excluded] as $action) {
|
||||
AuditLog::query()->create(['tenant_id' => $this->actor->tenant_id, 'user_id' => $this->actor->id,
|
||||
'action' => $action, 'after' => ['evidence' => 'SYNTHETIC-PRIVATE-PAYLOAD'], 'created_at' => now()]);
|
||||
AuditLog::query()->create(['tenant_id' => $foreign->id, 'user_id' => $foreignActor->id, 'action' => $action,
|
||||
'after' => ['evidence' => 'FOREIGN-SYNTHETIC-PRIVATE-PAYLOAD'], 'created_at' => now()]);
|
||||
}
|
||||
$before = DB::table('audit_logs')->orderBy('id')->get()->toJson();
|
||||
$sources = collectedPrivateAuditSources($this->actor, ['purchasing']);
|
||||
$events = $sources['purchasing:audit_logs']['rows'];
|
||||
foreach ($included as $action) {
|
||||
$matches = array_values(array_filter($events, fn ($row) => $row['action'] === $action));
|
||||
expect($matches)->toHaveCount(1)
|
||||
->and((int) $matches[0]['tenant_id'])->toBe($this->actor->tenant_id)
|
||||
->and($matches[0])->not->toHaveKey('after')->not->toHaveKey('before');
|
||||
}
|
||||
expect(array_column($events, 'action'))->not->toContain(...$excluded)
|
||||
->and(json_encode($events, JSON_THROW_ON_ERROR))->not->toContain('SYNTHETIC-PRIVATE-PAYLOAD')
|
||||
->and(DB::table('audit_logs')->orderBy('id')->get()->toJson())->toBe($before);
|
||||
foreach (['stock', 'finance', 'configuration'] as $family) {
|
||||
$other = collectedPrivateAuditSources($this->actor, [$family]);
|
||||
expect(array_column($other[$family.':audit_logs']['rows'], 'action'))->not->toContain(...$included);
|
||||
}
|
||||
});
|
||||
|
||||
test('audit links planning cancellation and warehouse return events to their own source family', function () {
|
||||
$families = ['purchasing' => ['planning.created', 'planning.linked', 'purchase_control.approved', 'cancellation.approved',
|
||||
'order_cancellation.approved', 'order_cancellation_policy.approved'],
|
||||
'stock' => ['warehouse_return.prepared', 'warehouse_return.confirmed', 'warehouse_return.cancelled']];
|
||||
foreach ($families as $actions) {
|
||||
foreach ($actions as $action) {
|
||||
AuditLog::query()->create(['tenant_id' => $this->actor->tenant_id, 'user_id' => $this->actor->id,
|
||||
'action' => $action, 'after' => ['synthetic' => true], 'created_at' => now()]);
|
||||
}
|
||||
}
|
||||
$before = DB::table('audit_logs')->orderBy('id')->get()->toJson();
|
||||
$sources = collectedPrivateAuditSources($this->actor, ['purchasing', 'stock', 'finance', 'configuration']);
|
||||
foreach ($families as $family => $actions) {
|
||||
expect(array_column($sources[$family.':audit_logs']['rows'], 'action'))->toContain(...$actions);
|
||||
foreach (array_diff(['purchasing', 'stock', 'finance', 'configuration'], [$family]) as $other) {
|
||||
expect(array_column($sources[$other.':audit_logs']['rows'], 'action'))->not->toContain(...$actions);
|
||||
}
|
||||
}
|
||||
expect(DB::table('audit_logs')->orderBy('id')->get()->toJson())->toBe($before);
|
||||
});
|
||||
|
||||
test('private audit exposes installed empty data separately from uninstalled optional common sources without calculations or writes', function () {
|
||||
$before = [];
|
||||
foreach (['budget_entries', 'stock_movements', 'external_payments', 'invoices', 'purchase_orders', 'audit_logs'] as $table) {
|
||||
|
||||
Reference in New Issue
Block a user