commit compras 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 13:49:31 +02:00
parent dc73540558
commit e709d900d1
81 changed files with 5352 additions and 107 deletions
@@ -3,6 +3,7 @@
use App\Models\Requisition;
use App\Services\ExternalPaymentWorkflow;
use App\Services\ProcurementPayableInsights;
use App\Services\ProcurementPaymentInsights;
use App\Services\SupplierPayables;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@@ -99,6 +100,45 @@ test('native imported history is counted once and pending payments do not reduce
expect($result['coverage']['recognised'])->toBe(1)->and($result['currencies'][0]['principal_minor'])->toBe('6000')
->and($result['currencies'][0]['confirmed_payments_minor'])->toBe('3000')->and($result['currencies'][0]['allocated_payments_minor'])->toBe('0')
->and($result['currencies'][0]['balance_minor'])->toBe('3000');
$confirmed = app(ProcurementPaymentInsights::class)->build($f['validator'], Requisition::query()->visibleTo($f['validator']), today()->format('Y-m-d'), today()->format('Y-m-d'));
expect($confirmed['coverage']['confirmed_payments'])->toBe(1)
->and($confirmed['currencies'])->toBe([['currency' => 'MZN', 'count' => 1, 'amount_minor' => '3000']]);
$outside = app(ProcurementPaymentInsights::class)->build($f['validator'], Requisition::query()->visibleTo($f['validator']), today()->subDay()->format('Y-m-d'), today()->subDay()->format('Y-m-d'));
expect($outside['currencies'])->toBe([]);
});
test('payment period follows confirmation instead of the original payment or requisition date and reports broken evidence', function () {
$f = paymentFixture();
foreach (['view', 'prepare', 'validate'] as $action) {
DB::table('pa_access')->insert(['tenant_id' => $f['validator']->tenant_id, 'company_id' => 0, 'unit_id' => 0,
'user_id' => $f['validator']->id, 'person' => 'period-person', 'action' => $action]);
}
$this->actingAs($f['author']);
$payment = app(ExternalPaymentWorkflow::class)->register($f['author'], $f['invoice'], $f['payment_data']);
$this->travel(1)->days();
$this->actingAs($f['validator']);
app(ExternalPaymentWorkflow::class)->review($f['validator'], $payment, 'confirmed', 'Conferência sintética independente');
$query = Requisition::query()->visibleTo($f['validator']);
$service = app(ProcurementPaymentInsights::class);
expect($service->build($f['validator'], clone $query, today()->format('Y-m-d'), today()->format('Y-m-d'))['currencies'][0]['amount_minor'])->toBe('4000')
->and($service->build($f['validator'], clone $query, today()->subDay()->format('Y-m-d'), today()->subDay()->format('Y-m-d'))['currencies'])->toBe([]);
if (DB::getDriverName() === 'pgsql') {
if (! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', DB::connection()->getDatabaseName()) || DB::transactionLevel() !== 1) {
throw new LogicException('Commit only the disposable report test fixture.');
}
DB::commit();
$this->committedInsightsFixture = true;
}
$this->get('/relatorios?from='.today()->format('Y-m-d').'&to='.today()->format('Y-m-d'))->assertOk()
->assertInertia(fn (Assert $page) => $page->where('records.total', 0)
->where('paymentInsights.coverage.confirmed_payments', 1)->where('paymentInsights.currencies.0.amount_minor', '4000'));
$csv = $this->get('/relatorios/despesa.csv?from='.today()->format('Y-m-d').'&to='.today()->format('Y-m-d'))->assertOk()->assertDownload();
expect($csv->streamedContent())->toContain('MZN;1;4000')->not->toContain('bank_snapshot')->not->toContain('account_identifier');
$this->actingAs($f['issuer'])->get('/relatorios/despesa.csv')->assertForbidden();
$this->actingAs($f['validator']);
DB::table('external_payments')->where('id', $payment->id)->update(['reviewed_at' => null]);
$broken = $service->build($f['validator'], clone $query, null, null);
expect($broken['coverage']['indeterminate'])->toBe(1)->and($broken['currencies'])->toBe([]);
});
test('read composition rejects commands and revalidates withdrawn native financial access', function () {