@@ -8,6 +8,7 @@ use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Services\PrivateAuditAccess;
|
||||
use App\Services\PrivateAuditSourceReader;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -187,3 +188,48 @@ test('private audit includes versioned import document metadata but excludes ban
|
||||
->and($rows[0]['purchase_order_id'])->toBe($this->f['order']->id)
|
||||
->and(json_encode($rows, JSON_THROW_ON_ERROR))->not->toContain('bank_commitment')->not->toContain('bank_support')->not->toContain('PRIVATE-PATH-NEVER-EXPORT');
|
||||
});
|
||||
|
||||
test('private financial audit scopes common settlement rows and outbox by tenant company and unit without bank references', function () {
|
||||
$schema = DB::getSchemaBuilder();
|
||||
foreach (['ps_payments', 'ps_events'] as $name) {
|
||||
$schema->create($name, function (Blueprint $table) use ($name) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('tenant_id');
|
||||
$table->unsignedBigInteger('company_id');
|
||||
$table->unsignedBigInteger('unit_id');
|
||||
if ($name === 'ps_payments') {
|
||||
$table->bigInteger('amount_minor');
|
||||
$table->string('fact_reference');
|
||||
$table->string('evidence_reference');
|
||||
$table->json('snapshot');
|
||||
} else {
|
||||
$table->unsignedBigInteger('payment_id');
|
||||
$table->unsignedBigInteger('actor_id');
|
||||
$table->string('kind');
|
||||
$table->json('payload');
|
||||
}
|
||||
});
|
||||
}
|
||||
$schema->create('ps_outbox', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('event_id')->primary();
|
||||
$table->string('state');
|
||||
});
|
||||
$foreign = Tenant::query()->create(['name' => 'Synthetic other common payment tenant']);
|
||||
$own = null;
|
||||
foreach ([[$this->actor->tenant_id, 0, 0], [$this->actor->tenant_id, 7, 0], [$this->actor->tenant_id, 0, 9], [$foreign->id, 0, 0]] as [$tenant, $company, $unit]) {
|
||||
$scope = ['tenant_id' => $tenant, 'company_id' => $company, 'unit_id' => $unit];
|
||||
$payment = DB::table('ps_payments')->insertGetId($scope + ['amount_minor' => 123,
|
||||
'fact_reference' => 'PRIVATE-BANK-FACT-SENTINEL', 'evidence_reference' => 'PRIVATE-BANK-EVIDENCE-SENTINEL',
|
||||
'snapshot' => json_encode(['account_identifier' => 'PRIVATE-BANK-SNAPSHOT-SENTINEL'], JSON_THROW_ON_ERROR)]);
|
||||
$event = DB::table('ps_events')->insertGetId($scope + ['payment_id' => $payment, 'actor_id' => $this->actor->id,
|
||||
'kind' => 'supplier_payment.confirmed', 'payload' => json_encode(['amount_minor' => 123,
|
||||
'account_identifier' => 'PRIVATE-BANK-PAYLOAD-SENTINEL'], JSON_THROW_ON_ERROR)]);
|
||||
DB::table('ps_outbox')->insert(['event_id' => $event, 'state' => 'captured']);
|
||||
$own ??= ['payment' => $payment, 'event' => $event];
|
||||
}
|
||||
$sources = collectedPrivateAuditSources($this->actor, ['finance']);
|
||||
expect(array_column($sources['finance:ps_payments']['rows'], 'id'))->toBe([$own['payment']])
|
||||
->and(array_column($sources['finance:ps_events']['rows'], 'id'))->toBe([$own['event']])
|
||||
->and($sources['finance:ps_outbox']['rows'])->toBe([['event_id' => $own['event'], 'state' => 'captured']])
|
||||
->and(json_encode($sources, JSON_THROW_ON_ERROR))->not->toContain('PRIVATE-BANK-');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user