@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use App\Services\ExpenseAllocations;
|
||||
use App\Services\ExternalPaymentWorkflow;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
require_once __DIR__.'/PaymentFixture.php';
|
||||
|
||||
/** Native payment originals and exact, labelled synthetic categories; guarded by receiptFixture. */
|
||||
function expenseAllocationQaFixture(): array
|
||||
{
|
||||
$f = paymentFixture(['Material', 'Serviços']);
|
||||
config(['common-payables.enabled' => true, 'common-payables.source_instance' => 'explicit-expense-qa', 'expense-allocations.qa_enabled' => true]);
|
||||
foreach ([$f['author'], $f['validator']] as $actor) {
|
||||
DB::table('pa_access')->insert(['tenant_id' => $actor->tenant_id, 'company_id' => 0, 'unit_id' => 0, 'user_id' => $actor->id,
|
||||
'person' => 'expense-qa-'.$actor->id, 'action' => 'view']);
|
||||
}
|
||||
auth()->guard()->setUser($f['author']);
|
||||
$payment = app(ExternalPaymentWorkflow::class)->register($f['author'], $f['invoice'], $f['payment_data']);
|
||||
auth()->guard()->setUser($f['validator']);
|
||||
app(ExternalPaymentWorkflow::class)->review($f['validator'], $payment, 'confirmed', 'Conferência de evidência estritamente sintética');
|
||||
$source = app(ExpenseAllocations::class)->source($f['validator'], $payment->id);
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'fingerprint' => $source['fingerprint'],
|
||||
'reason' => 'Imputação explícita de Finanças no ensaio sintético',
|
||||
'allocations' => [['category' => 'Material', 'amount' => '15.00'], ['category' => 'Serviços', 'amount' => '25.00']]];
|
||||
|
||||
return compact('f', 'payment', 'source', 'input');
|
||||
}
|
||||
@@ -7,15 +7,18 @@ use App\Services\BudgetWorkflow;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\InvoiceWorkflow;
|
||||
use App\Services\ReceiptWorkflow;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
require_once __DIR__.'/ReceiptFixture.php';
|
||||
|
||||
/** Synthetic data: receiptFixture enforces an isolated test database. */
|
||||
function invoiceFixture(): array
|
||||
function invoiceFixture(array $categories = ['Material']): array
|
||||
{
|
||||
$f = receiptFixture();
|
||||
app(ReceiptWorkflow::class)->confirm($f['receiver'], $f['order'], receiptPayload($f, '1.000'));
|
||||
$f = receiptFixture('1.000', 'consumable', $categories);
|
||||
$receipt = receiptPayload($f, '1.000');
|
||||
$receipt['items'] = array_map(fn ($line) => [...$receipt['items'][0], 'purchase_order_item_id' => $line->id], $f['lines']);
|
||||
app(ReceiptWorkflow::class)->confirm($f['receiver'], $f['order'], $receipt);
|
||||
$author = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
|
||||
$validator = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
|
||||
auth()->guard()->setUser($author);
|
||||
@@ -26,6 +29,8 @@ function invoiceFixture(): array
|
||||
app(BudgetWorkflow::class)->record($author, $f['r'], 'commit', 10000, 10000);
|
||||
});
|
||||
$data = ['number' => 'FT-PG-1', 'issued_on' => today()->format('Y-m-d'), 'subtotal' => '60.00', 'tax' => '0.00', 'total' => '60.00', 'items' => [['purchase_order_item_id' => $f['line']->id, 'quantity' => '0.600', 'unit' => 'cx', 'unit_price' => '100.00', 'tax_rate' => '0']]];
|
||||
$data['items'] = array_map(fn ($line) => ['purchase_order_item_id' => $line->id, 'quantity' => '0.600', 'unit' => 'cx',
|
||||
'unit_price' => (string) BigDecimal::of($line->unit_price_minor)->dividedBy(100, 2), 'tax_rate' => '0'], $f['lines']);
|
||||
$invoice = app(InvoiceWorkflow::class)->register($author, $f['order'], $data);
|
||||
|
||||
return [...$f, 'author' => $author, 'validator' => $validator, 'invoice' => $invoice, 'data' => $data];
|
||||
|
||||
@@ -24,11 +24,26 @@ function landedQaReceiptsVerified(array $command, string $output): bool
|
||||
return false;
|
||||
};
|
||||
$mode = ($command[1] ?? '') === 'vendor/bin/pest' ? 'pest' : ($command[3] ?? '');
|
||||
if ($mode === 'recover-cycles') {
|
||||
if ($mode === 'race-expense') {
|
||||
foreach (['same_operation', 'same_version'] as $scenario) {
|
||||
$matches = array_values(array_filter($records, fn ($row) => ($row['scenario'] ?? null) === $scenario));
|
||||
if (count($matches) !== 1 || ($matches[0]['blocked_writers_observed'] ?? 0) < 2 || ($matches[0]['expense_versions_created'] ?? null) !== 1
|
||||
|| ($matches[0]['audits'] ?? null) !== 1 || ($matches[0]['financial_sources_unchanged'] ?? false) !== true
|
||||
|| ($matches[0]['statuses'] ?? null) !== ($scenario === 'same_operation' ? [200, 200] : [200, 409])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
if (in_array($mode, ['recover-cycles', 'recover-expenses'], true)) {
|
||||
return $contains(fn ($row) => ($row['cycle_post_extension_all_tables_equal'] ?? false) === true
|
||||
&& ($row['cycle_native_replays_without_effects'] ?? false) === true && ($row['cycle_history_and_reserve_restored'] ?? false) === true
|
||||
&& ($row['cycle_reserved_minor'] ?? null) === 12000 && ($row['cycle_pre_extension_all_tables_equal'] ?? false) === true)
|
||||
&& $contains(fn ($row) => ($row['isolated_restore_removed'] ?? false) === true);
|
||||
&& $contains(fn ($row) => ($row['isolated_restore_removed'] ?? false) === true)
|
||||
&& ($mode !== 'recover-expenses' || $contains(fn ($row) => ($row['expense_versions_restored'] ?? null) === 2
|
||||
&& ($row['expense_native_sources_verified'] ?? false) === true && ($row['expense_replay_without_effects'] ?? false) === true
|
||||
&& ($row['expense_explicit_amounts_restored'] ?? null) === ['Material' => '1000', 'Serviços' => '3000']));
|
||||
}
|
||||
if ($mode === 'race-cycles') {
|
||||
foreach (['same_operation', 'different_operations', 'late_decision'] as $scenario) {
|
||||
@@ -41,7 +56,10 @@ function landedQaReceiptsVerified(array $command, string $output): bool
|
||||
}
|
||||
}
|
||||
|
||||
return $contains(fn ($row) => ($row['old_cycle_runtime_rejected_before_balance'] ?? false) === true && ($row['status'] ?? null) === 503);
|
||||
return $contains(fn ($row) => ($row['old_cycle_runtime_rejected_before_balance'] ?? false) === true && ($row['status'] ?? null) === 503)
|
||||
&& $contains(fn ($row) => ($row['scheduled_expiry_without_session'] ?? false) === true && ($row['scheduled_scope_closed'] ?? false) === true
|
||||
&& ($row['scheduled_repeat_without_effects'] ?? false) === true && ($row['scheduled_audit_explicit'] ?? false) === true
|
||||
&& ($row['scheduled_unrelated_operations_denied'] ?? null) === 3);
|
||||
}
|
||||
if ($mode === 'capital') {
|
||||
if (! $contains(fn ($row) => ($row['capital_register_versions_restored'] ?? null) === 2
|
||||
@@ -100,7 +118,7 @@ function landedQaReceiptsVerified(array $command, string $output): bool
|
||||
&& $contains(fn ($row) => ($row['isolated_restore_removed'] ?? false) === true);
|
||||
}
|
||||
|
||||
if (in_array($mode, ['legal-http', 'legal-review'], true)) {
|
||||
if (in_array($mode, ['legal-http', 'legal-review', 'expiry-review'], true)) {
|
||||
return $contains(fn ($row) => ($row['native_legal_http_login'] ?? false) === true && ($row['csrf_required'] ?? false) === true
|
||||
&& ($row['large_multipart_upload_bytes'] ?? 0) > 2097152 && ($row['original_unchanged'] ?? false) === true
|
||||
&& ($row['exact_native_download'] ?? false) === true && ($row['one_source_one_audit_after_replay'] ?? false) === true
|
||||
|
||||
@@ -7,9 +7,9 @@ use App\Services\SupplierBankWorkflow;
|
||||
require_once __DIR__.'/InvoiceFixture.php';
|
||||
|
||||
/** invoiceFixture enforces a synthetic, isolated test database. */
|
||||
function paymentFixture(): array
|
||||
function paymentFixture(array $categories = ['Material']): array
|
||||
{
|
||||
$f = invoiceFixture();
|
||||
$f = invoiceFixture($categories);
|
||||
auth()->guard()->setUser($f['validator']);
|
||||
app(InvoiceWorkflow::class)->validate($f['validator'], $f['invoice']);
|
||||
$supplier = Supplier::query()->findOrFail($f['order']->supplier_id);
|
||||
|
||||
@@ -16,7 +16,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/** Synthetic fixture: callable only on in-memory SQLite or the dedicated PostgreSQL test database. */
|
||||
function receiptFixture(string $quantity = '1.000', string $purchaseType = 'consumable'): array
|
||||
function receiptFixture(string $quantity = '1.000', string $purchaseType = 'consumable', array $categories = ['Material']): array
|
||||
{
|
||||
$connection = DB::connection();
|
||||
$allowed = ($connection->getDriverName() === 'sqlite' && $connection->getDatabaseName() === ':memory:') ||
|
||||
@@ -24,6 +24,15 @@ function receiptFixture(string $quantity = '1.000', string $purchaseType = 'cons
|
||||
if (! app()->environment('testing') || ! $allowed) {
|
||||
throw new LogicException('Fixtures de recepção proibidas fora de uma base de testes isolada.');
|
||||
}
|
||||
if ($categories === [] || count($categories) > 100 || 10000 % count($categories) !== 0 || count(array_unique($categories)) !== count($categories)) {
|
||||
throw new LogicException('Synthetic categories require an exact explicit split of the fixture total.');
|
||||
}
|
||||
if (count($categories) > 1 && $quantity !== '1.000') {
|
||||
throw new LogicException('The explicit multi-category fixture uses one unit per line.');
|
||||
}
|
||||
$lineMinor = intdiv(10000, count($categories));
|
||||
$amounts = \App\Services\PurchaseLineAmounts::portion($lineMinor, '0', 0, \App\Services\ReceiptWorkflow::milli($quantity));
|
||||
$documentMinor = $amounts['total_minor'] * count($categories);
|
||||
$tenant = Tenant::query()->create(['name' => 'Empresa fictícia de recepção']);
|
||||
$department = Department::query()->create(['tenant_id' => $tenant->id, 'name' => 'Operações']);
|
||||
$center = CostCenter::query()->create(['tenant_id' => $tenant->id, 'department_id' => $department->id, 'code' => 'OPS', 'name' => 'Operações']);
|
||||
@@ -31,17 +40,25 @@ function receiptFixture(string $quantity = '1.000', string $purchaseType = 'cons
|
||||
$receiver = User::factory()->create(['tenant_id' => $tenant->id, 'department_id' => $department->id, 'purchasing_role' => PurchasingRole::Warehouse]);
|
||||
$otherReceiver = User::factory()->create(['tenant_id' => $tenant->id, 'department_id' => $department->id, 'purchasing_role' => PurchasingRole::Warehouse]);
|
||||
auth()->guard()->setUser($receiver);
|
||||
$r = Requisition::query()->create(['tenant_id' => $tenant->id, 'requester_id' => $issuer->id, 'department_id' => $department->id, 'cost_center_id' => $center->id, 'number' => 'REQ-TEST-'.Str::random(10), 'priority' => 'normal', 'needed_by' => now()->addWeek(), 'justification' => 'Fixture de ordem já emitida para testes de recepção.', 'status' => 'approved', 'subtotal_minor' => 10000, 'tax_minor' => 0, 'total_minor' => 10000]);
|
||||
$requested = $r->items()->create(['tenant_id' => $tenant->id, 'description' => 'Artigo fictício', 'category' => 'Material', 'purchase_type' => $purchaseType, 'quantity' => $quantity, 'unit' => 'cx', 'unit_price_minor' => 10000, 'tax_rate' => '0', 'subtotal_minor' => 10000, 'tax_minor' => 0, 'total_minor' => 10000]);
|
||||
$r = Requisition::query()->create(['tenant_id' => $tenant->id, 'requester_id' => $issuer->id, 'department_id' => $department->id, 'cost_center_id' => $center->id, 'number' => 'REQ-TEST-'.Str::random(10), 'priority' => 'normal', 'needed_by' => now()->addWeek(), 'justification' => 'Fixture de ordem já emitida para testes de recepção.', 'status' => 'approved', 'subtotal_minor' => $documentMinor, 'tax_minor' => 0, 'total_minor' => $documentMinor]);
|
||||
$requested = $r->items()->create(['tenant_id' => $tenant->id, 'description' => 'Artigo fictício', 'category' => $categories[0], 'purchase_type' => $purchaseType, 'quantity' => $quantity, 'unit' => 'cx', 'unit_price_minor' => $lineMinor, 'tax_rate' => '0', ...$amounts]);
|
||||
$supplier = Supplier::query()->create(['tenant_id' => $tenant->id, 'created_by' => $issuer->id, 'name' => 'Fornecedor fictício', 'nuit' => '123456789', 'contact' => 'Contacto de teste', 'email' => 'fixture@example.invalid', 'phone' => '000000000', 'address' => 'Morada fictícia', 'category' => 'Material', 'beneficiaries' => 'Beneficiário fictício', 'document_references' => 'Documento fictício', 'diligence_notes' => 'Somente para a base de testes.', 'status' => 'active', 'next_review' => now()->addYear()]);
|
||||
$quote = Quotation::query()->create(['tenant_id' => $tenant->id, 'requisition_id' => $r->id, 'supplier_id' => $supplier->id, 'created_by' => $issuer->id, 'reference' => 'PROP-TEST', 'delivery_days' => 5, 'valid_until' => now()->addWeek(), 'payment_terms' => '30 dias', 'subtotal_minor' => 10000, 'tax_minor' => 0, 'total_minor' => 10000, 'weights' => ['price' => 40, 'quality' => 20, 'delivery' => 15, 'history' => 15, 'payment' => 10]]);
|
||||
$award = PurchaseAward::query()->create(['tenant_id' => $tenant->id, 'requisition_id' => $r->id, 'quotation_id' => $quote->id, 'created_by' => $issuer->id, 'justification' => 'Adjudicação de fixture, não repetir o fluxo anterior.', 'delivery_date' => now()->addWeek(), 'delivery_location' => 'Armazém fictício', 'status' => 'approved', 'subtotal_minor' => 10000, 'tax_minor' => 0, 'total_minor' => 10000, 'approval_snapshot' => [], 'decision_matrix' => [], 'comparison_hash' => str_repeat('0', 64)]);
|
||||
$order = PurchaseOrder::query()->create(['tenant_id' => $tenant->id, 'requisition_id' => $r->id, 'purchase_award_id' => $award->id, 'supplier_id' => $supplier->id, 'issued_by' => $issuer->id, 'number' => 'OC-TEST-'.Str::random(10), 'status' => 'issued', 'currency' => 'MZN', 'subtotal_minor' => 10000, 'tax_minor' => 0, 'total_minor' => 10000, 'issued_at' => now(), 'snapshot' => ['supplier' => $supplier->only(['name', 'nuit']), 'company' => ['name' => $tenant->name], 'development_only' => true, 'budget_checked' => false]]);
|
||||
$line = $order->items()->create(['tenant_id' => $tenant->id, 'requisition_item_id' => $requested->id, 'description' => 'Artigo fictício', 'category' => 'Material', 'purchase_type' => $purchaseType, 'unit' => 'cx', 'quantity' => $quantity, 'unit_price_minor' => 10000, 'tax_rate' => '0', 'subtotal_minor' => 10000, 'tax_minor' => 0, 'total_minor' => 10000]);
|
||||
$quote = Quotation::query()->create(['tenant_id' => $tenant->id, 'requisition_id' => $r->id, 'supplier_id' => $supplier->id, 'created_by' => $issuer->id, 'reference' => 'PROP-TEST', 'delivery_days' => 5, 'valid_until' => now()->addWeek(), 'payment_terms' => '30 dias', 'subtotal_minor' => $documentMinor, 'tax_minor' => 0, 'total_minor' => $documentMinor, 'weights' => ['price' => 40, 'quality' => 20, 'delivery' => 15, 'history' => 15, 'payment' => 10]]);
|
||||
$award = PurchaseAward::query()->create(['tenant_id' => $tenant->id, 'requisition_id' => $r->id, 'quotation_id' => $quote->id, 'created_by' => $issuer->id, 'justification' => 'Adjudicação de fixture, não repetir o fluxo anterior.', 'delivery_date' => now()->addWeek(), 'delivery_location' => 'Armazém fictício', 'status' => 'approved', 'subtotal_minor' => $documentMinor, 'tax_minor' => 0, 'total_minor' => $documentMinor, 'approval_snapshot' => [], 'decision_matrix' => [], 'comparison_hash' => str_repeat('0', 64)]);
|
||||
$order = PurchaseOrder::query()->create(['tenant_id' => $tenant->id, 'requisition_id' => $r->id, 'purchase_award_id' => $award->id, 'supplier_id' => $supplier->id, 'issued_by' => $issuer->id, 'number' => 'OC-TEST-'.Str::random(10), 'status' => 'issued', 'currency' => 'MZN', 'subtotal_minor' => $documentMinor, 'tax_minor' => 0, 'total_minor' => $documentMinor, 'issued_at' => now(), 'snapshot' => ['supplier' => $supplier->only(['name', 'nuit']), 'company' => ['name' => $tenant->name], 'development_only' => true, 'budget_checked' => false]]);
|
||||
$line = $order->items()->create(['tenant_id' => $tenant->id, 'requisition_item_id' => $requested->id, 'description' => 'Artigo fictício', 'category' => $categories[0], 'purchase_type' => $purchaseType, 'unit' => 'cx', 'quantity' => $quantity, 'unit_price_minor' => $lineMinor, 'tax_rate' => '0', ...$amounts]);
|
||||
$lines = [$line];
|
||||
foreach (array_slice($categories, 1) as $category) {
|
||||
$additional = $requested->replicate();
|
||||
$additional->fill(['category' => $category])->save();
|
||||
$copy = $line->replicate();
|
||||
$copy->fill(['category' => $category, 'requisition_item_id' => $additional->id])->save();
|
||||
$lines[] = $copy;
|
||||
}
|
||||
$warehouse = Warehouse::query()->create(['tenant_id' => $tenant->id, 'created_by' => $receiver->id, 'code' => 'ARM-TEST', 'name' => 'Armazém fictício']);
|
||||
$stock = StockItem::query()->create(['tenant_id' => $tenant->id, 'created_by' => $receiver->id, 'code' => 'ART-TEST', 'name' => 'Artigo de stock fictício', 'unit' => 'cx']);
|
||||
|
||||
return compact('tenant', 'department', 'issuer', 'receiver', 'otherReceiver', 'r', 'order', 'line', 'warehouse', 'stock');
|
||||
return compact('tenant', 'department', 'issuer', 'receiver', 'otherReceiver', 'r', 'order', 'line', 'lines', 'warehouse', 'stock');
|
||||
}
|
||||
|
||||
function receiptPayload(array $fixture, string $quantity = '0.600'): array
|
||||
|
||||
@@ -30,7 +30,7 @@ $app->booted(function () use ($root, $database) {
|
||||
if (config('database.default') !== 'pgsql' || config('database.connections.pgsql.database') !== $database) {
|
||||
abort(503);
|
||||
}
|
||||
config(['capital-register.qa_enabled' => true, 'import-legal.qa_enabled' => true, 'import-tariffs.qa_enabled' => true,
|
||||
config(['requisition-expiry.qa_enabled' => true, 'capital-register.qa_enabled' => true, 'import-legal.qa_enabled' => true, 'import-tariffs.qa_enabled' => true,
|
||||
'import-dossier.qa_enabled' => true, 'import-bank-support.qa_enabled' => true, 'import-readiness.qa_enabled' => true, 'import-estimates.qa_enabled' => true,
|
||||
'session.driver' => 'file', 'session.files' => $root.'/storage/framework/sessions', 'session.domain' => null,
|
||||
'session.secure' => false, 'cache.default' => 'array']);
|
||||
|
||||
Reference in New Issue
Block a user