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

This commit is contained in:
2026-11-27 18:11:02 +02:00
parent e709d900d1
commit 930064269e
74 changed files with 7506 additions and 40 deletions
+55
View File
@@ -9,6 +9,8 @@ use App\Models\User;
use App\Services\CommonBudget;
use App\Services\ImportEstimates;
use App\Services\ImportLandedCosts;
use App\Services\ImportLegalEstimates;
use App\Services\ImportLegalRules;
use App\Services\ImportTariffCodes;
use App\Services\RequisitionWorkflow;
use App\Services\SupplyPlanning;
@@ -24,6 +26,7 @@ use Tempo\Finance\Budget\BudgetImportEstimate;
require_once __DIR__.'/../Support/ReceiptFixture.php';
require_once __DIR__.'/../Support/SupplyFixture.php';
require_once __DIR__.'/../Support/ImportLegalQaFixture.php';
beforeEach(function () {
if (! class_exists(BudgetImportEstimate::class)) {
@@ -54,6 +57,58 @@ beforeEach(function () {
'subtotal_minor' => null, 'tax_minor' => null, 'total_minor' => null], BudgetImportEstimate::KINDS)];
});
test('native import cost assumptions reuse exact legal charges once with explicit tax split and immutable source provenance', function () {
config(['import-legal.qa_enabled' => true, 'import-tariffs.qa_enabled' => true]);
Storage::fake('local');
supplyGrant($this->f['issuer'], ['procurement', 'import_customs']);
$rules = app(ImportLegalRules::class);
$draft = $rules->save($this->f['issuer'], importLegalQaInput(['charges' => [[
'key' => 'synthetic-duty', 'kind' => 'duty', 'label' => 'Synthetic duty', 'method' => 'ad_valorem', 'rate_percent' => '7.5',
'specific_minor' => null, 'quantity_unit' => null, 'basis_reference' => 'Synthetic explicit customs-value basis',
]]]), importLegalQaFile());
$rule = $rules->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $draft->record_key,
'version' => 1, 'action' => 'publish', 'reason' => 'Synthetic rate publication for native estimate integration']);
$legal = app(ImportLegalEstimates::class)->save($this->f['issuer'], $this->draft, ['operation_key' => (string) Str::uuid(), 'version' => 0,
'requisition_item_id' => $this->draft->items()->sole()->id, 'rule_id' => $rule->id, 'match_code' => '1234', 'origin' => 'Synthetic A',
'sector' => 'Synthetic sector', 'date' => '2026-11-27', 'bases' => ['synthetic-duty' => ['value_minor' => 10000,
'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic declared customs valuation']], 'reason' => 'Synthetic exact charge adoption fixture']);
$input = $this->input;
foreach ($input['components'] as &$component) {
$component['status'] = $component['kind'] === 'duty' ? 'known' : 'not_applicable';
$component['basis'] = 'Explicit synthetic assumptions; other costs do not apply in this test';
if ($component['kind'] === 'duty') {
$component['subtotal_minor'] = 750;
$component['tax_minor'] = 0;
$component['total_minor'] = 750;
}
}
unset($component);
$input['legal_sources'] = ['duty' => ['estimate_id' => $legal->id, 'charge_key' => 'synthetic-duty']];
$native = app(ImportEstimates::class)->save($this->f['issuer'], $this->draft, $input);
expect($native->snapshot['plan']['budget_amount_minor'])->toBe(10750)
->and($native->snapshot['legal_sources']['duty']['estimate_id'])->toBe($legal->id)
->and($native->snapshot['legal_sources']['duty']['legal_rule']['id'])->toBe($rule->id)
->and(DB::table('budget_entries')->count())->toBe(0);
$changed = [...$input, 'operation_key' => (string) Str::uuid(), 'version' => 1];
foreach ($changed['components'] as &$component) {
if ($component['kind'] === 'duty') {
$component['subtotal_minor'] = 751;
$component['total_minor'] = 751;
}
}
unset($component);
expect(fn () => app(ImportEstimates::class)->save($this->f['issuer'], $this->draft, $changed))->toThrow(HttpException::class);
$duplicate = [...$input, 'operation_key' => (string) Str::uuid(), 'version' => 1];
$duty = array_values(array_filter($duplicate['components'], fn ($component) => $component['kind'] === 'duty'))[0];
$duplicate['components'][] = [...$duty, 'key' => 'duty-again'];
$duplicate['legal_sources']['duty-again'] = $duplicate['legal_sources']['duty'];
expect(fn () => app(ImportEstimates::class)->save($this->f['issuer'], $this->draft, $duplicate))->toThrow(HttpException::class);
$rules->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $rule->record_key,
'version' => 2, 'action' => 'withdraw', 'reason' => 'Synthetic withdrawal before native approval requires explicit review']);
expect(fn () => app(ImportEstimates::class)->approval($this->draft))->toThrow(HttpException::class);
expect(DB::table('budget_entries')->count())->toBe(0)->and($native->fresh()->snapshot['plan']['budget_amount_minor'])->toBe(10750);
});
test('native draft assumptions preserve unknowns originals and versions without financial or stock effects', function () {
$service = app(ImportEstimates::class);
$before = $this->draft->fresh()->getAttributes();