@@ -110,6 +110,17 @@ test('allocation enforces current Finance access and refuses unavailable or unau
|
||||
expect(SupplyRecord::query()->where('kind', 'expense_allocation')->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('denied expense attribution provides a Portuguese return path without exposing the financial source or changing JSON refusals', function () {
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$url = '/pagamentos/'.$this->payment->id.'/categorias';
|
||||
$this->get($url)->assertForbidden()->assertSee('Acesso reservado')->assertSee('Voltar ao painel')
|
||||
->assertSee('lang="pt-MZ"', false)->assertDontSee($this->f['invoice']->number)
|
||||
->assertDontSee('TEST-PAY-ACCOUNT')->assertDontSee('TEST-EXT-01');
|
||||
$this->getJson($url)->assertForbidden()->assertJsonStructure(['message'])
|
||||
->assertDontSee('<!DOCTYPE html>', false)->assertDontSee('TEST-PAY-ACCOUNT');
|
||||
expect(SupplyRecord::query()->where('kind', 'expense_allocation')->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('incomplete confirmation or missing allocation audit keeps analytical attribution indeterminate', function () {
|
||||
$actor = $this->f['validator'];
|
||||
$this->service->save($actor, $this->payment->id, $this->input);
|
||||
|
||||
@@ -59,6 +59,50 @@ test('unknown rates and missing bases never become zero while explicit non-appli
|
||||
expect(fn () => $amounts->calculate([legalCharge(['rate_percent' => '10000'])], ['synthetic-duty' => ['value_minor' => 100000000000000, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic overflow boundary']]))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('specific coefficients preserve fractional cents and round only the final exact charge', function () {
|
||||
$amounts = app(ImportLegalAmounts::class);
|
||||
$charge = legalCharge(['method' => 'specific', 'rate_percent' => null, 'specific_minor' => '1.33', 'quantity_unit' => 'g']);
|
||||
// Synthetic quantity: 600 L * 10.6 g/100 ml * 10 = 63600 g.
|
||||
// Coefficient0.0133 MZN/g corresponds exactly to1.33 cents/g.
|
||||
$base = ['value_minor' => null, 'quantity' => '63600.000000', 'quantity_unit' => 'g', 'source' => 'Synthetic documented quantity and concentration; no implicit conversion'];
|
||||
expect($amounts->definitions([$charge])[0]['specific_minor'])->toBe('1.33')
|
||||
->and($amounts->calculate([$charge], ['synthetic-duty' => $base])['total_minor'])->toBe(84588)
|
||||
->and($amounts->calculate([[...$charge, 'specific_minor' => '0.99']], ['synthetic-duty' => $base])['total_minor'])->toBe(62964);
|
||||
foreach (['0.499999' => 0, '0.500000' => 1] as $coefficient => $expected) {
|
||||
expect($amounts->calculate([[...$charge, 'specific_minor' => $coefficient]], ['synthetic-duty' => [...$base, 'quantity' => '1']])['total_minor'])->toBe($expected);
|
||||
}
|
||||
expect($amounts->definitions([[...$charge, 'specific_minor' => '125.000000']])[0]['specific_minor'])->toBe(125);
|
||||
foreach (['0.0000001', '1e2', '-0.1', '100000000000000.000001', 0.99] as $invalid) {
|
||||
expect(fn () => $amounts->definitions([[...$charge, 'specific_minor' => $invalid]]))->toThrow(ValidationException::class);
|
||||
}
|
||||
$maximum = [...$charge, 'method' => 'maximum', 'rate_percent' => '7.5', 'specific_minor' => '0.99'];
|
||||
expect($amounts->calculate([$maximum], ['synthetic-duty' => [...$base, 'value_minor' => 10001, 'quantity' => '1000']])['total_minor'])->toBe(990);
|
||||
});
|
||||
|
||||
test('native fractional specific estimates preserve the coefficient source and replay without financial effects', function () {
|
||||
$rules = app(ImportLegalRules::class);
|
||||
$charge = legalCharge(['method' => 'specific', 'rate_percent' => null, 'specific_minor' => '0.99', 'quantity_unit' => 'g']);
|
||||
$draft = $rules->save($this->f['issuer'], importLegalQaInput(['charges' => [$charge]]), importLegalQaFile());
|
||||
$rule = $rules->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $draft->record_key, 'version' => 1,
|
||||
'action' => 'publish', 'reason' => 'Synthetic fractional coefficient verification, no real tax activation']);
|
||||
$before = [];
|
||||
foreach (['budget_entries', 'invoices', 'stock_movements'] as $table) {
|
||||
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
|
||||
}
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'requisition_item_id' => $this->f['r']->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' => null, 'quantity' => '63600', 'quantity_unit' => 'g', 'source' => 'Synthetic explicit sugar mass']],
|
||||
'reason' => 'Synthetic exact coefficient estimate without a budget or stock effect'];
|
||||
$service = app(ImportLegalEstimates::class);
|
||||
$record = $service->save($this->f['issuer'], $this->f['r'], $input);
|
||||
expect($rule->data['charges'][0]['specific_minor'])->toBe('0.99')
|
||||
->and($record->snapshot['result']['total_minor'])->toBe(62964)
|
||||
->and($service->save($this->f['issuer'], $this->f['r'], $input)->id)->toBe($record->id);
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
});
|
||||
|
||||
test('native estimates freeze source bases and calculated results without reserving funds and reject stale versions', function () {
|
||||
$rules = app(ImportLegalRules::class);
|
||||
$draft = $rules->save($this->f['issuer'], importLegalQaInput(['charges' => [legalCharge()]]), importLegalQaFile());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Services\ImportLegalAmounts;
|
||||
use App\Services\ImportLegalReferenceDrafts;
|
||||
use App\Services\ImportLegalRules;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
@@ -36,7 +37,7 @@ test('a supplied official edition offers exact documentary drafts without publis
|
||||
new UploadedFile($path, basename($path), 'application/pdf', UPLOAD_ERR_OK, true));
|
||||
$workspace = $service->workspace($this->f['issuer'], $this->f['r']);
|
||||
$drafts = $workspace['referenceDrafts'];
|
||||
expect($drafts)->toHaveCount(11)
|
||||
expect($drafts)->toHaveCount(48)
|
||||
->and(array_column($drafts, 'code'))->toContain('3506.91.20', '7604.10.10')
|
||||
->and($drafts[0]['rate_percent'])->toBe('20')
|
||||
->and($drafts[2]['rate_percent'])->toBe('7.5')
|
||||
@@ -44,9 +45,28 @@ test('a supplied official edition offers exact documentary drafts without publis
|
||||
->and($drafts[0]['citation'])->toContain('2180-(4)')
|
||||
->and($drafts[0]['source_id'])->toBe($source->id)
|
||||
->and($drafts[0]['charges'][0]['kind'])->toBe('duty')
|
||||
->and($drafts[0]['charges'])->toHaveCount(4)
|
||||
->and($workspace['referenceDraftWarnings'])->toBe([])
|
||||
->and(SupplyRecord::query()->where('kind', 'import_legal_rule')->count())->toBe(0)
|
||||
->and(json_encode($workspace['sources'], JSON_THROW_ON_ERROR))->not->toContain('import-legal/');
|
||||
expect(array_unique(array_column($drafts, 'code')))->toHaveCount(48);
|
||||
$capital = collect($drafts)->firstWhere('code', '8451.80.10');
|
||||
$vehicle = collect($drafts)->firstWhere('code', '8704.21.10');
|
||||
$last = collect($drafts)->firstWhere('code', '9507.90.90');
|
||||
expect($capital['rate_percent'])->toBe('5')->and($capital['documentary_class'])->toBe('K')
|
||||
->and($capital['obligations'])->toContain('não comprova elegibilidade')
|
||||
->and($capital['citation'])->toContain('2180-(5)')
|
||||
->and($vehicle['documentary_class'])->toBeNull()
|
||||
->and($vehicle['obligations'])->toContain('bens de capital para investimento')
|
||||
->and($last['citation'])->toContain('2180-(7)')
|
||||
->and($last['rate_percent'])->toBe('5');
|
||||
// A purely illustrative 100 MZN base is not a real import, debt or complete tax assessment.
|
||||
$estimate = app(ImportLegalAmounts::class)->calculate($drafts[0]['charges'], ['general_duty' => [
|
||||
'value_minor' => 10000, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Explicit synthetic 100 MZN unit-test base']]);
|
||||
expect($estimate['known_subtotal_minor'])->toBe(2000)
|
||||
->and($estimate['complete'])->toBeFalse()
|
||||
->and($estimate['total_minor'])->toBeNull()
|
||||
->and($estimate['financial_effects'])->toBeFalse();
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
|
||||
@@ -157,3 +157,27 @@ test('private audit packages remain personal to their creator even within the sa
|
||||
$this->withoutVite()->get('/auditoria/privada')->assertOk()->assertViewHas('page', fn (array $page) => $page['props']['exports']['data'] === []);
|
||||
expect(PrivateAuditExport::query()->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('private audit detects a missing archive and accepts only the exact recovered private bytes without regenerating history', function () {
|
||||
Storage::fake('audit_recovery');
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'families' => ['configuration']];
|
||||
$service = app(PrivateAuditExporter::class);
|
||||
$export = $service->generate($this->actor, $input);
|
||||
$archive = Storage::disk('local')->get($export->path);
|
||||
Storage::disk('audit_recovery')->put('original.zip', $archive);
|
||||
$before = DB::table('private_audit_exports')->where('id', $export->id)->first();
|
||||
$events = DB::table('audit_logs')->count();
|
||||
// Remove only the known generated file in the disposable fake QA disk.
|
||||
Storage::disk('local')->delete($export->path);
|
||||
try {
|
||||
$service->generate($this->actor, $input);
|
||||
test()->fail('Missing historical packages must not be silently regenerated.');
|
||||
} catch (HttpException $error) {
|
||||
expect($error->getStatusCode())->toBe(409);
|
||||
}
|
||||
Storage::disk('local')->put($export->path, Storage::disk('audit_recovery')->get('original.zip'));
|
||||
expect($service->generate($this->actor, $input)->id)->toBe($export->id)
|
||||
->and(hash_file('sha256', $service->verifiedPath($this->actor, $export)))->toBe($export->sha256)
|
||||
->and(DB::table('private_audit_exports')->where('id', $export->id)->first())->toEqual($before)
|
||||
->and(DB::table('audit_logs')->count())->toBe($events);
|
||||
});
|
||||
|
||||
@@ -511,6 +511,8 @@ test('native expiry returns the same request and preserves the approved stage be
|
||||
->where('history.data.0.rules.first_limit_minor', 5000)->where('history.data.0.rules.approval_includes_tax', true)
|
||||
->where('history.data.0.approval_amount_minor', 10000)->where('history.data.0.approval_uses_separate_basis', false)
|
||||
->where('history.data.0.steps.0.approver_id', $head->id)->where('history.data.0.steps.0.comment', 'Conferência sintética do primeiro nível')
|
||||
->where('history.data.0.steps.0.decided_at', CarbonImmutable::parse($approved['decided_at'], config('app.timezone'))->toIso8601String())
|
||||
->where('history.data.0.steps.1.decided_at', null)
|
||||
->missing('history.data.0.rules.timing')->missing('history.data.0.items.0.category_context'));
|
||||
foreach ($beforeHistoryRead as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
|
||||
Reference in New Issue
Block a user