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

This commit is contained in:
2026-11-27 20:19:21 +02:00
parent 7486007fcf
commit d58b75c87a
57 changed files with 2803 additions and 116 deletions
@@ -1,9 +1,12 @@
<?php
use App\Models\PurchaseAward;
use App\Models\Quotation;
use App\Models\Requisition;
use App\Services\ExternalPaymentWorkflow;
use App\Services\ProcurementPayableInsights;
use App\Services\ProcurementPaymentInsights;
use App\Services\SupplierBankWorkflow;
use App\Services\SupplierPayables;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@@ -12,6 +15,65 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
require_once __DIR__.'/../Support/PaymentFixture.php';
test('supplier payment groups paginate independently while the export projection retains every group', function () {
$f = $this->f;
$this->actingAs($f['validator']);
// Synthetic invoice chains for read coverage; payment originals use the native registration/review workflow.
$originalAward = PurchaseAward::query()->findOrFail($f['order']->purchase_award_id);
$originalQuote = Quotation::query()->findOrFail($originalAward->quotation_id);
foreach (range(1, 21) as $index) {
$request = $f['r']->replicate();
$request->fill(['number' => 'SYNTHETIC-GROUP-'.$index])->save();
$supplier = $f['supplier']->replicate();
$supplier->fill(['name' => $index === 21 ? '=1+1' : 'Synthetic supplier '.$index, 'nuit' => (string) (500000000 + $index)])->save();
$quote = $originalQuote->replicate();
$quote->fill(['requisition_id' => $request->id, 'supplier_id' => $supplier->id, 'reference' => 'SYNTHETIC-GROUP-'.$index])->save();
$award = $originalAward->replicate();
$award->fill(['requisition_id' => $request->id, 'quotation_id' => $quote->id])->save();
$order = $f['order']->replicate();
$order->fill(['requisition_id' => $request->id, 'supplier_id' => $supplier->id, 'purchase_award_id' => $award->id, 'number' => 'SYNTHETIC-GROUP-'.$index,
'snapshot' => [...$f['order']->snapshot, 'supplier' => $supplier->only(['name', 'nuit'])]])->save();
$invoice = $f['invoice']->fresh()->replicate();
$invoice->fill(['supplier_id' => $supplier->id, 'purchase_order_id' => $order->id, 'number' => 'SYNTHETIC-GROUP-'.$index,
'snapshot' => [...$f['invoice']->snapshot, 'supplier' => $supplier->only(['name', 'nuit']), 'order_number' => $order->number]])->save();
$this->actingAs($f['issuer']);
$bank = app(SupplierBankWorkflow::class)->propose($f['issuer'], $supplier,
[...$f['bank_data'], 'account_identifier' => 'SYNTHETIC-GROUP-'.$index]);
foreach ([$f['author'], $f['validator']] as $reviewer) {
$this->actingAs($reviewer);
app(SupplierBankWorkflow::class)->review($reviewer, $bank, 'approved', 'Independent synthetic account review');
}
$this->actingAs($f['author']);
$payment = app(ExternalPaymentWorkflow::class)->register($f['author'], $invoice,
[...$f['payment_data'], 'supplier_bank_detail_id' => $bank->id, 'external_reference' => 'SYNTHETIC-GROUP-'.$index]);
$this->actingAs($f['validator']);
app(ExternalPaymentWorkflow::class)->review($f['validator'], $payment, 'confirmed', 'Independent synthetic payment evidence review');
}
$service = app(ProcurementPaymentInsights::class);
$query = Requisition::query()->visibleTo($f['validator']);
$first = $service->build($f['validator'], clone $query, null, null, 1);
$last = $service->build($f['validator'], clone $query, null, null, 2);
$all = $service->build($f['validator'], clone $query, null, null, null);
expect($first['suppliers']['data'])->toHaveCount(20)->and($last['suppliers']['data'])->toHaveCount(1)
->and($all['suppliers']['data'])->toHaveCount(21)->and($all['suppliers']['total'])->toBe(21)
->and($first['currencies'])->toBe($last['currencies'])->and($all['currencies'][0]['amount_minor'])->toBe('84000')
->and($all['coverage']['confirmed_payments'])->toBe(21)
->and(array_intersect(array_column($first['suppliers']['data'], 'supplier_id'), array_column($last['suppliers']['data'], 'supplier_id')))->toBe([]);
if (DB::getDriverName() === 'pgsql') {
if (DB::connection()->getConfig('host') !== '127.0.0.1' || ! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', DB::connection()->getDatabaseName()) || DB::transactionLevel() !== 1) {
throw new LogicException('Commit only the disposable supplier report fixture.');
}
DB::commit();
$this->committedInsightsFixture = true;
}
$before = [DB::table('external_payments')->count(), DB::table('audit_logs')->count()];
$this->get('/relatorios?supplier_page=2')->assertOk()->assertInertia(fn (Assert $page) => $page->has('paymentInsights.suppliers.data', 1)
->where('paymentInsights.suppliers.current_page', 2)->where('paymentInsights.suppliers.total', 21));
$csv = $this->get('/relatorios/despesa.csv?supplier_page=2')->assertOk()->assertDownload()->streamedContent();
expect(substr_count($csv, 'Synthetic supplier'))->toBe(20)->and($csv)->toContain(";'=1+1;MZN;1;4000")
->and([DB::table('external_payments')->count(), DB::table('audit_logs')->count()])->toBe($before);
});
beforeEach(function () {
$this->f = paymentFixture();
config(['common-payables.enabled' => true, 'common-payables.source_instance' => 'insights-fixture-instance']);
@@ -121,6 +183,9 @@ test('payment period follows confirmation instead of the original payment or req
$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, null, null)['suppliers']['data'][0])->toMatchArray([
'supplier_id' => $f['supplier']->id, 'supplier_name' => $f['invoice']->snapshot['supplier']['name'],
'currency' => 'MZN', 'count' => 1, 'amount_minor' => '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) {
@@ -133,7 +198,8 @@ test('payment period follows confirmation instead of the original payment or req
->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');
expect($csv->streamedContent())->toContain('MZN;1;4000')->toContain('Nome conservado na factura')
->toContain((string) $f['supplier']->id)->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]);