@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
use App\Models\CriticalityLevel;
|
||||
use App\Models\Equipment;
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Services\CapitalAssignments;
|
||||
use App\Services\CapitalRegister;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
|
||||
beforeEach(function () {
|
||||
config(['capital-register.qa_enabled' => true]);
|
||||
$this->withoutVite();
|
||||
$this->f = receiptFixture();
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$this->input = ['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0,
|
||||
'type' => 'project', 'code' => 'PRJ-QA', 'name' => 'Projecto estritamente sintético',
|
||||
'department_id' => $this->f['department']->id, 'equipment_id' => null,
|
||||
'reference' => 'Documento fictício para cadastro independente de Compras', 'state' => 'active',
|
||||
'reason' => 'Preparação de referência sintética para testes de compras'];
|
||||
});
|
||||
|
||||
test('own project register versions preserves identity and replay without financial or stock effects', function () {
|
||||
$service = app(CapitalRegister::class);
|
||||
$before = [];
|
||||
foreach (['budget_entries', 'stock_movements', 'invoices', 'purchase_orders'] as $table) {
|
||||
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
|
||||
}
|
||||
$first = $service->save($this->f['issuer'], $this->input);
|
||||
expect($first->version)->toBe(1)->and($first->snapshot['source_system'])->toBe('compras');
|
||||
expect($service->save($this->f['issuer'], $this->input)->id)->toBe($first->id);
|
||||
$archive = [...$this->input, 'operation_key' => (string) Str::uuid(), 'record_key' => $first->record_key, 'version' => 1, 'state' => 'archived'];
|
||||
$second = $service->save($this->f['issuer'], $archive);
|
||||
expect($second->version)->toBe(2)->and($second->state)->toBe('archived')
|
||||
->and($first->fresh()->state)->toBe('active')->and(SupplyRecord::query()->where('kind', 'capital_register')->count())->toBe(2);
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$archive, 'operation_key' => (string) Str::uuid()]))->toThrow(HttpException::class);
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid()]))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('register rejects reused operation content and renaming a permanent code', function () {
|
||||
$service = app(CapitalRegister::class);
|
||||
$first = $service->save($this->f['issuer'], $this->input);
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$this->input, 'name' => 'Conteúdo diferente']))->toThrow(HttpException::class);
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(),
|
||||
'record_key' => $first->record_key, 'version' => 1, 'code' => 'OUTRO']))->toThrow(ValidationException::class);
|
||||
expect(SupplyRecord::query()->where('kind', 'capital_register')->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('asset references reuse a physical equipment identity and reject duplicate or removed links', function () {
|
||||
$level = CriticalityLevel::query()->create(['tenant_id' => $this->f['tenant']->id, 'created_by' => $this->f['issuer']->id, 'created_at' => now(), 'code' => 'QA', 'name' => 'Ensaio', 'criteria' => 'Só fixture sintética', 'is_critical' => false]);
|
||||
$equipment = Equipment::query()->create(['tenant_id' => $this->f['tenant']->id, 'created_by' => $this->f['issuer']->id, 'code' => 'EQ-QA', 'description' => 'Equipamento físico sintético',
|
||||
'area' => 'Área sintética', 'status' => 'active', 'department_id' => $this->f['department']->id, 'criticality_level_id' => $level->id]);
|
||||
$input = [...$this->input, 'type' => 'asset', 'code' => 'ASSET-QA', 'equipment_id' => $equipment->id];
|
||||
$service = app(CapitalRegister::class);
|
||||
$first = $service->save($this->f['issuer'], $input);
|
||||
expect($first->snapshot['equipment']['id'])->toBe($equipment->id)->and(Equipment::query()->count())->toBe(1);
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$input, 'operation_key' => (string) Str::uuid(), 'code' => 'OTHER-QA']))->toThrow(ValidationException::class);
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$input, 'operation_key' => (string) Str::uuid(), 'record_key' => $first->record_key, 'version' => 1, 'equipment_id' => null]))->toThrow(ValidationException::class);
|
||||
$this->get('/projectos-imobilizado?history='.$first->record_key)->assertOk()->assertInertia(fn (Assert $page) => $page->has('history.data', 1));
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$input, 'operation_key' => (string) Str::uuid(), 'code' => ['invalid']]))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('native register page is encrypted private paginated and gated off outside QA', function () {
|
||||
app(CapitalRegister::class)->save($this->f['issuer'], $this->input);
|
||||
$this->get('/projectos-imobilizado')->assertOk()->assertHeader('Cache-Control', 'max-age=0, no-store, private')
|
||||
->assertViewHas('page', fn (array $page) => $page['encryptHistory'] === true)
|
||||
->assertInertia(fn (Assert $page) => $page->component('equipment/capital-register')
|
||||
->has('records.data', 1)->where('records.data.0.data.code', 'PRJ-QA')->where('canManage', true));
|
||||
config(['capital-register.qa_enabled' => false]);
|
||||
$this->get('/projectos-imobilizado')->assertStatus(503);
|
||||
});
|
||||
|
||||
test('native register revalidates operator and hides foreign department identity without creating versions', function () {
|
||||
$service = app(CapitalRegister::class);
|
||||
$first = $service->save($this->f['issuer'], $this->input);
|
||||
$this->actingAs($this->f['receiver']);
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid()]))->toThrow(HttpException::class);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$other = receiptFixture();
|
||||
$this->actingAs($other['issuer']);
|
||||
$this->get('/projectos-imobilizado')->assertOk()->assertInertia(fn (Assert $page) => $page->has('records.data', 0));
|
||||
$this->post('/projectos-imobilizado', [...$this->input, 'operation_key' => (string) Str::uuid(), 'record_key' => $first->record_key, 'version' => 1])->assertNotFound();
|
||||
$this->actingAs($this->f['issuer']);
|
||||
expect(SupplyRecord::query()->where('kind', 'capital_register')->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('line destination freezes the chosen project version and preserves it after archival without financial effects', function () {
|
||||
$register = app(CapitalRegister::class);
|
||||
$source = $register->save($this->f['issuer'], $this->input);
|
||||
$this->f['r']->update(['status' => 'draft']);
|
||||
$item = $this->f['r']->items()->firstOrFail();
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'item_id' => $item->id,
|
||||
'capital_id' => $source->id, 'reason' => 'Escolha de destino sintético da linha da requisição'];
|
||||
$service = app(CapitalAssignments::class);
|
||||
$first = $service->save($this->f['issuer'], $this->f['r'], $input);
|
||||
expect($first->state)->toBe('linked')->and($service->save($this->f['issuer'], $this->f['r'], $input)->id)->toBe($first->id);
|
||||
$register->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(),
|
||||
'record_key' => $source->record_key, 'version' => 1, 'state' => 'archived', 'name' => 'Designação posterior sintética']);
|
||||
$frozen = $service->freezeForItems($this->f['issuer'], [$item->id]);
|
||||
expect($frozen[$item->id]['snapshot']['source']['version'])->toBe(1)
|
||||
->and($frozen[$item->id]['snapshot']['source']['data']['name'])->toBe($this->input['name']);
|
||||
$this->get('/requisicoes/'.$this->f['r']->id.'/projectos-imobilizado')->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page->component('requisitions/capital-assignments')->where('canWrite', true)->has('choices.data', 0)->has('current', 1));
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->f['r'], [...$input, 'operation_key' => (string) Str::uuid(), 'version' => 1]))->toThrow(ModelNotFoundException::class);
|
||||
expect(DB::table('budget_entries')->count())->toBe(0)->and(DB::table('stock_movements')->count())->toBe(0);
|
||||
$item->update(['description' => 'Artigo alterado após a escolha']);
|
||||
expect(fn () => $service->freezeForItems($this->f['issuer'], [$item->id]))->toThrow(HttpException::class);
|
||||
$cleared = $service->save($this->f['issuer'], $this->f['r'], [...$input, 'operation_key' => (string) Str::uuid(), 'version' => 1, 'capital_id' => null]);
|
||||
expect($cleared->state)->toBe('cleared')->and($service->freezeForItems($this->f['issuer'], [$item->id]))->toBe([])
|
||||
->and($first->fresh()->state)->toBe('linked');
|
||||
});
|
||||
|
||||
test('submitted requisitions reject new line destinations and stale versions do not replace choices', function () {
|
||||
$source = app(CapitalRegister::class)->save($this->f['issuer'], $this->input);
|
||||
$item = $this->f['r']->items()->firstOrFail();
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'item_id' => $item->id, 'capital_id' => $source->id,
|
||||
'reason' => 'Escolha documental sintética preservando decisões anteriores'];
|
||||
$service = app(CapitalAssignments::class);
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->f['r'], $input))->toThrow(HttpException::class);
|
||||
$this->f['r']->update(['status' => 'draft']);
|
||||
$service->save($this->f['issuer'], $this->f['r'], $input);
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->f['r'], [...$input, 'operation_key' => (string) Str::uuid(), 'capital_id' => null]))->toThrow(HttpException::class);
|
||||
config(['capital-register.qa_enabled' => false]);
|
||||
expect(fn () => $service->freezeForItems($this->f['issuer'], [$item->id]))->toThrow(HttpException::class);
|
||||
expect(SupplyRecord::query()->where('kind', 'capital_assignment')->count())->toBe(1);
|
||||
});
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Models\User;
|
||||
use App\Services\ImportBankSupport;
|
||||
use App\Services\ImportDossier;
|
||||
use App\Services\SupplyPlanning;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
|
||||
function bankSupportOriginal(object $test, string $type, string $reference, ?SupplyRecord $previous = null): SupplyRecord
|
||||
{
|
||||
return app(ImportDossier::class)->record($test->f['issuer'], $test->import, ['operation_key' => (string) Str::uuid(), 'type' => $type,
|
||||
'record_key' => $previous?->record_key, 'version' => $previous?->version ?? 0, 'reference' => $reference,
|
||||
'issuer_reference' => 'Synthetic issuing entity', 'issued_on' => today()->toDateString(), 'notes' => 'Synthetic bank-support evidence only.',
|
||||
'reason' => 'Preservar original sintético para o acompanhamento bancário'],
|
||||
UploadedFile::fake()->createWithContent('bank-support.pdf', "%PDF-1.4\nSynthetic original ".$reference."\n%%EOF"));
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
config(['import-dossier.qa_enabled' => true, 'import-bank-support.qa_enabled' => true]);
|
||||
Storage::fake('local');
|
||||
$this->withoutVite();
|
||||
$this->f = receiptFixture();
|
||||
supplyGrant($this->f['issuer'], ['procurement', 'import_prepare']);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$this->import = app(SupplyPlanning::class)->save($this->f['issuer'], 'import', supplyInput([
|
||||
'purchase_order_id' => $this->f['order']->id, 'purpose' => 'internal', 'jurisdiction' => 'Synthetic bank-support jurisdiction',
|
||||
'origin_country' => 'Synthetic A', 'dispatch_country' => 'Synthetic B', 'regime' => 'Synthetic documentary regime']));
|
||||
$this->term = bankSupportOriginal($this, 'bank_commitment', 'BANK-TERM-QA');
|
||||
$this->declaration = bankSupportOriginal($this, 'customs_declaration', 'DU-QA');
|
||||
$this->invoice = bankSupportOriginal($this, 'commercial_invoice', 'INVOICE-QA-1');
|
||||
$this->input = ['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0,
|
||||
'commitment_document_id' => $this->term->id, 'declaration_document_id' => $this->declaration->id,
|
||||
'support_document_ids' => [$this->invoice->id], 'requirements_known' => true,
|
||||
'required_support_types' => ['commercial_invoice'], 'required_support_counts' => ['commercial_invoice' => 2],
|
||||
'requirements_basis' => 'Synthetic bank request explicitly asks for two commercial invoices',
|
||||
'submission_document_id' => null, 'submission_basis' => null, 'submitted_on' => null,
|
||||
'due_on' => today()->subDay()->toDateString(), 'deadline_basis' => 'Explicit synthetic bank letter deadline, not a legal default',
|
||||
'reason' => 'Acompanhamento estritamente documental e sintético'];
|
||||
});
|
||||
|
||||
test('bank support preserves exact requested counts versions and original delivery evidence without payment or JUE effects', function () {
|
||||
$service = app(ImportBankSupport::class);
|
||||
$before = [DB::table('stock_movements')->get()->toJson(), DB::table('invoices')->get()->toJson(), DB::table('budget_entries')->get()->toJson(), $this->import->fresh()->getAttributes()];
|
||||
$first = $service->save($this->f['issuer'], $this->import, $this->input);
|
||||
expect($first->state)->toBe('tracking')->and($service->save($this->f['issuer'], $this->import, $this->input)->id)->toBe($first->id)
|
||||
->and(implode(' ', $service->issues($first)))->toContain('Factura comercial (1)', 'Prazo documental ultrapassado', 'não demonstra a entrega');
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->import, [...$this->input, 'operation_key' => (string) Str::uuid()]))->toThrow(HttpException::class);
|
||||
$invoice = bankSupportOriginal($this, 'commercial_invoice', 'INVOICE-QA-2');
|
||||
$secondInput = [...$this->input, 'operation_key' => (string) Str::uuid(), 'record_key' => $first->record_key, 'version' => 1,
|
||||
'support_document_ids' => [$this->invoice->id, $invoice->id]];
|
||||
$ready = $service->save($this->f['issuer'], $this->import, $secondInput);
|
||||
expect($ready->state)->toBe('ready')->and(implode(' ', $service->issues($ready)))->toContain('Prazo documental ultrapassado');
|
||||
$delivery = bankSupportOriginal($this, 'bank_support', 'BANK-DELIVERY-QA-1');
|
||||
$thirdInput = [...$secondInput, 'operation_key' => (string) Str::uuid(), 'version' => 2,
|
||||
'submission_document_id' => $delivery->id, 'submission_basis' => 'Synthetic documentary delivery receipt; no live bank action', 'submitted_on' => today()->toDateString()];
|
||||
$documented = $service->save($this->f['issuer'], $this->import, $thirdInput);
|
||||
expect($documented->state)->toBe('documented')->and($service->issues($documented))->toBe(['Entrega documentada após o prazo indicado.'])
|
||||
->and($documented->snapshot['bank_transfer_executed'])->toBeFalse()->and($documented->snapshot['jue_submission_executed'])->toBeFalse()
|
||||
->and($documented->snapshot['bank_compliance_certified'])->toBeFalse();
|
||||
$correction = bankSupportOriginal($this, 'bank_support', 'BANK-DELIVERY-QA-2', $delivery);
|
||||
expect(implode(' ', $service->issues($documented)))->toContain('foi corrigido', 'Prazo documental ultrapassado');
|
||||
$fourth = $service->save($this->f['issuer'], $this->import, [...$thirdInput, 'operation_key' => (string) Str::uuid(), 'version' => 3, 'submission_document_id' => $correction->id]);
|
||||
expect($fourth->version)->toBe(4)->and($service->issues($fourth))->toBe(['Entrega documentada após o prazo indicado.'])->and($first->fresh()->state)->toBe('tracking')
|
||||
->and([DB::table('stock_movements')->get()->toJson(), DB::table('invoices')->get()->toJson(), DB::table('budget_entries')->get()->toJson(), $this->import->fresh()->getAttributes()])->toBe($before);
|
||||
});
|
||||
|
||||
test('unknown bank requirements and deadlines stay unknown and cannot silently become a completed or zero-day obligation', function () {
|
||||
$record = app(ImportBankSupport::class)->save($this->f['issuer'], $this->import, [...$this->input,
|
||||
'requirements_known' => false, 'required_support_types' => [], 'required_support_counts' => [], 'declaration_document_id' => null,
|
||||
'due_on' => null, 'deadline_basis' => null]);
|
||||
expect($record->state)->toBe('tracking')->and($record->data['due_on'])->toBeNull()
|
||||
->and(implode(' ', app(ImportBankSupport::class)->issues($record)))->toContain('desconhecidos', 'Prazo documental ainda por indicar');
|
||||
expect(fn () => app(ImportBankSupport::class)->save($this->f['issuer'], $this->import, [...$this->input, 'deadline_basis' => ' ']))->toThrow(HttpException::class);
|
||||
expect(fn () => app(ImportBankSupport::class)->save($this->f['issuer'], $this->import, [...$this->input, 'required_support_counts' => []]))->toThrow(HttpException::class);
|
||||
$delivery = bankSupportOriginal($this, 'bank_support', 'DELIVERY-UNKNOWN-DATE');
|
||||
expect(fn () => app(ImportBankSupport::class)->save($this->f['issuer'], $this->import, [...$this->input,
|
||||
'submission_document_id' => $delivery->id, 'submission_basis' => 'Synthetic delivery evidence with no event date']))->toThrow(HttpException::class);
|
||||
expect(fn () => app(ImportBankSupport::class)->save($this->f['issuer'], $this->import, [...$this->input,
|
||||
'submission_document_id' => $delivery->id, 'submission_basis' => 'Synthetic delivery cannot be recorded as already occurred tomorrow',
|
||||
'submitted_on' => today()->addDay()->toDateString()]))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('bank follow-up rejects foreign documents wrong types stale versions and withdrawn write authority', function () {
|
||||
$service = app(ImportBankSupport::class);
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->import, [...$this->input, 'commitment_document_id' => $this->invoice->id]))->toThrow(HttpException::class);
|
||||
$record = $service->save($this->f['issuer'], $this->import, $this->input);
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->import, [...$this->input, 'record_key' => $record->record_key, 'operation_key' => (string) Str::uuid()]))->toThrow(HttpException::class);
|
||||
$other = receiptFixture();
|
||||
supplyGrant($other['issuer'], ['procurement', 'import_prepare']);
|
||||
$this->actingAs($other['issuer']);
|
||||
$otherImport = app(SupplyPlanning::class)->save($other['issuer'], 'import', supplyInput([
|
||||
'purchase_order_id' => $other['order']->id, 'purpose' => 'internal', 'jurisdiction' => 'Other synthetic jurisdiction',
|
||||
'origin_country' => 'Synthetic A', 'dispatch_country' => 'Synthetic B', 'regime' => 'Synthetic documentary regime']));
|
||||
$otherDocument = bankSupportOriginal((object) ['f' => $other, 'import' => $otherImport], 'bank_commitment', 'OTHER-BANK-TERM');
|
||||
expect(fn () => $service->save($other['issuer'], $this->import, $this->input))->toThrow(ModelNotFoundException::class);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->import, [...$this->input, 'operation_key' => (string) Str::uuid(),
|
||||
'commitment_document_id' => $otherDocument->id]))->toThrow(ModelNotFoundException::class);
|
||||
DB::table('organization_memberships')->where('user_id', $this->f['issuer']->id)->delete();
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->import, [...$this->input, 'operation_key' => (string) Str::uuid()]))->toThrow(HttpException::class);
|
||||
});
|
||||
|
||||
test('native bank entry consultation and full-scope CSV share source data permissions and formula-safe references', function () {
|
||||
$term = bankSupportOriginal($this, 'bank_commitment', '=SYNTHETIC-REFERENCE');
|
||||
$input = [...$this->input, 'commitment_document_id' => $term->id];
|
||||
$url = '/compras/importacoes/'.$this->import->id.'/suporte-bancario';
|
||||
$this->post($url, $input)->assertRedirect();
|
||||
$record = SupplyRecord::query()->where('kind', 'import_bank_support')->where('operation_key', $input['operation_key'])->firstOrFail();
|
||||
$this->post($url, $input)->assertRedirect();
|
||||
expect(SupplyRecord::query()->where('kind', 'import_bank_support')->count())->toBe(1);
|
||||
$tables = ['users', 'supply_records', 'audit_logs', 'budget_entries', 'invoices', 'stock_movements'];
|
||||
$before = [];
|
||||
foreach ($tables as $table) {
|
||||
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
|
||||
}
|
||||
$this->get($url)->assertOk()->assertHeader('Cache-Control', 'max-age=0, no-store, private')
|
||||
->assertInertia(fn (AssertableInertia $page) => $page->component('supply/import-bank-support')
|
||||
->where('canWrite', true)->where('current.data.0.id', $record->id)->where('current.data.0.data.required_support_counts.commercial_invoice', 2)
|
||||
->missing('current.data.0.snapshot.documents.0.path'));
|
||||
$csv = $this->get($url.'.csv?bank_current_page=999999')->assertOk()->assertDownload();
|
||||
expect($csv->streamedContent())->toContain("'=SYNTHETIC-REFERENCE", 'Factura comercial: 2', 'Prazo documental ultrapassado')
|
||||
->not->toContain('import-dossier/', 'account_identifier');
|
||||
foreach ($tables as $table) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($before[$table]);
|
||||
}
|
||||
$viewer = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'purchasing_role' => PurchasingRole::Finance]);
|
||||
supplyGrant($viewer, ['finance']);
|
||||
$this->actingAs($viewer)->get($url)->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->where('canWrite', false));
|
||||
$this->post($url, [...$input, 'operation_key' => (string) Str::uuid()])->assertForbidden();
|
||||
config(['import-bank-support.qa_enabled' => false]);
|
||||
$this->get($url)->assertStatus(503);
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use App\Services\ImportLegalAmounts;
|
||||
use App\Services\ImportLegalEstimates;
|
||||
use App\Services\ImportLegalRules;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
require_once __DIR__.'/../Support/ImportLegalQaFixture.php';
|
||||
|
||||
function legalCharge(array $overrides = []): array
|
||||
{
|
||||
return [...['key' => 'synthetic-duty', 'kind' => 'duty', 'label' => 'Synthetic duty', 'method' => 'ad_valorem',
|
||||
'rate_percent' => '7.5', 'specific_minor' => null, 'quantity_unit' => null,
|
||||
'basis_reference' => 'Synthetic customs-value basis; not an approved real legal rule'], ...$overrides];
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
config(['import-legal.qa_enabled' => true, 'import-tariffs.qa_enabled' => true]);
|
||||
Storage::fake('local');
|
||||
$this->withoutVite();
|
||||
$this->f = receiptFixture();
|
||||
supplyGrant($this->f['issuer'], ['procurement', 'import_customs']);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
});
|
||||
|
||||
test('ad valorem specific and the greater-value method use exact decimals and documented units', function () {
|
||||
$amounts = app(ImportLegalAmounts::class);
|
||||
$base = ['value_minor' => 10001, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic explicit customs valuation'];
|
||||
$result = $amounts->calculate([legalCharge()], ['synthetic-duty' => $base]);
|
||||
expect($result['total_minor'])->toBe(750)->and($result['financial_effects'])->toBeFalse();
|
||||
$specific = legalCharge(['method' => 'specific', 'rate_percent' => null, 'specific_minor' => 125, 'quantity_unit' => 'KG']);
|
||||
expect($amounts->calculate([$specific], ['synthetic-duty' => [...$base, 'value_minor' => null, 'quantity' => '1.500', 'quantity_unit' => 'KG']])['total_minor'])->toBe(188);
|
||||
$maximum = legalCharge(['method' => 'maximum', 'specific_minor' => 1000, 'quantity_unit' => 'KG']);
|
||||
expect($amounts->calculate([$maximum], ['synthetic-duty' => [...$base, 'quantity' => '1.500', 'quantity_unit' => 'KG']])['total_minor'])->toBe(1500);
|
||||
expect($amounts->calculate([$maximum], ['synthetic-duty' => [...$base, 'quantity' => '0.100', 'quantity_unit' => 'KG']])['total_minor'])->toBe(750);
|
||||
expect(fn () => $amounts->calculate([$maximum], ['synthetic-duty' => [...$base, 'quantity' => '1.5', 'quantity_unit' => 'BOX']]))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('unknown rates and missing bases never become zero while explicit non-application and zero rates remain distinct', function () {
|
||||
$amounts = app(ImportLegalAmounts::class);
|
||||
$unknown = legalCharge(['key' => 'unknown', 'method' => 'unknown', 'rate_percent' => null]);
|
||||
$zero = legalCharge(['key' => 'zero', 'rate_percent' => '0']);
|
||||
$notApplicable = legalCharge(['key' => 'not-applicable', 'method' => 'not_applicable', 'rate_percent' => null]);
|
||||
$result = $amounts->calculate([$unknown, $zero, $notApplicable], ['zero' => ['value_minor' => 10000, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic declared base'],
|
||||
'not-applicable' => ['value_minor' => null, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic documentary proof that all non-application prerequisites are met']]);
|
||||
expect($result['complete'])->toBeFalse()->and($result['total_minor'])->toBeNull()->and($result['known_subtotal_minor'])->toBe(0)
|
||||
->and(array_column($result['lines'], 'amount_minor'))->toBe([null, 0, 0]);
|
||||
expect($amounts->calculate([], [])['total_minor'])->toBeNull();
|
||||
expect($amounts->calculate([$notApplicable], [])['total_minor'])->toBeNull();
|
||||
expect($amounts->calculate([legalCharge()], [])['total_minor'])->toBeNull();
|
||||
expect(fn () => $amounts->definitions([legalCharge(['method' => 'unknown'])]))->toThrow(ValidationException::class);
|
||||
expect(fn () => $amounts->calculate([legalCharge()], ['synthetic-duty' => ['value_minor' => 10000, 'quantity' => null, 'quantity_unit' => null, 'source' => null]]))->toThrow(ValidationException::class);
|
||||
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('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());
|
||||
$rule = $rules->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $draft->record_key, 'version' => 1,
|
||||
'action' => 'publish', 'reason' => 'Synthetic explicit customs rate review for estimates']);
|
||||
$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' => 10001, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic exact customs valuation']],
|
||||
'reason' => 'Synthetic estimate with explicit source and no financial effects'];
|
||||
$before = [DB::table('budget_entries')->get()->toJson(), DB::table('invoices')->get()->toJson(), DB::table('stock_movements')->get()->toJson()];
|
||||
$url = '/requisicoes/'.$this->f['r']->id.'/base-legal/estimativas';
|
||||
$this->post($url, $input)->assertRedirect();
|
||||
$service = app(ImportLegalEstimates::class);
|
||||
$record = $service->save($this->f['issuer'], $this->f['r'], $input);
|
||||
expect($record->snapshot['result']['total_minor'])->toBe(750)->and($record->snapshot['legal_rule']['id'])->toBe($rule->id)
|
||||
->and($service->save($this->f['issuer'], $this->f['r'], $input)->id)->toBe($record->id);
|
||||
expect(fn () => $service->save($this->f['issuer'], $this->f['r'], [...$input, 'operation_key' => (string) Str::uuid()]))->toThrow(HttpException::class);
|
||||
$second = $service->save($this->f['issuer'], $this->f['r'], [...$input, 'operation_key' => (string) Str::uuid(), 'version' => 1, 'bases' => []]);
|
||||
expect($second->state)->toBe('indeterminate')->and($second->snapshot['result']['total_minor'])->toBeNull()
|
||||
->and($record->fresh()->snapshot['result']['total_minor'])->toBe(750)
|
||||
->and($service->forPlan($this->f['r'], $record->id)->id)->toBe($record->id)
|
||||
->and([DB::table('budget_entries')->get()->toJson(), DB::table('invoices')->get()->toJson(), DB::table('stock_movements')->get()->toJson()])->toBe($before);
|
||||
});
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Models\User;
|
||||
use App\Services\ImportEvidence;
|
||||
use App\Services\ImportLegalRules;
|
||||
use App\Services\ImportTariffCodes;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
|
||||
function legalRuleInput(array $overrides = []): array
|
||||
{
|
||||
return [...['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0, 'action' => 'save',
|
||||
'title' => 'Synthetic tariff rule', 'official_reference' => 'Synthetic official edition QA only',
|
||||
'official_url' => 'https://example.test/official-qa.pdf', 'citation' => 'Synthetic article 1, page 2',
|
||||
'valid_from' => '2026-01-01', 'valid_until' => '2026-12-31', 'match_code' => '1234', 'suggested_code' => '1234.56',
|
||||
'origin_country' => 'Synthetic A', 'sector' => 'Synthetic sector', 'obligations' => 'Synthetic duty conditions; no real tax activated',
|
||||
'document_types' => ['licence'], 'reason' => 'Synthetic legal configuration; not an approved real legal rule'], ...$overrides];
|
||||
}
|
||||
|
||||
function legalRuleFile(): UploadedFile
|
||||
{
|
||||
return UploadedFile::fake()->createWithContent('source.pdf', "%PDF-1.4\nSynthetic official source for QA only\n%%EOF");
|
||||
}
|
||||
|
||||
function publishLegalRule(User $actor, SupplyRecord $draft): SupplyRecord
|
||||
{
|
||||
return app(ImportLegalRules::class)->save($actor, ['operation_key' => (string) Str::uuid(), 'record_key' => $draft->record_key,
|
||||
'version' => $draft->version, 'action' => 'publish', 'reason' => 'Synthetic customs review and publication of the prepared rule']);
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
config(['import-tariffs.qa_enabled' => true, 'import-legal.qa_enabled' => true]);
|
||||
Storage::fake('local');
|
||||
$this->withoutVite();
|
||||
$this->f = receiptFixture();
|
||||
supplyGrant($this->f['issuer'], ['procurement', 'import_customs']);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
});
|
||||
|
||||
test('legal publication preserves sources versions periods scope and previous publication during a draft revision', function () {
|
||||
$service = app(ImportLegalRules::class);
|
||||
$before = [DB::table('budget_entries')->get()->toJson(), DB::table('invoices')->get()->toJson(), DB::table('stock_movements')->get()->toJson()];
|
||||
$input = legalRuleInput();
|
||||
$file = legalRuleFile();
|
||||
$draft = $service->save($this->f['issuer'], $input, $file);
|
||||
expect($service->save($this->f['issuer'], $input, $file)->id)->toBe($draft->id);
|
||||
$find = fn ($origin = 'Synthetic A', $sector = 'Synthetic sector', $date = '2026-11-27') => $service->suggestions($this->f['issuer'], $this->f['r'], '1234', $origin, $sector, $date);
|
||||
expect($find())->toBe([]);
|
||||
$published = publishLegalRule($this->f['issuer'], $draft);
|
||||
expect($find()[0]['id'])->toBe($published->id)->and($find(''))->toBe([])->and($find('Synthetic A', ''))->toBe([])
|
||||
->and($find('Synthetic A', 'Synthetic sector', '2027-01-01'))->toBe([])
|
||||
->and($find('Synthetic A', 'Synthetic sector', '2026-01-01'))->toHaveCount(1)
|
||||
->and($find('Synthetic A', 'Synthetic sector', '2026-12-31'))->toHaveCount(1);
|
||||
$frozen = $service->freeze($published->id, '1234', 'Synthetic A', 'Synthetic sector', '2026-11-27');
|
||||
$next = $service->save($this->f['issuer'], legalRuleInput(['record_key' => $published->record_key, 'version' => 2, 'suggested_code' => '1234.57']));
|
||||
expect($find()[0]['id'])->toBe($published->id)->and($service->changed($frozen))->toBeFalse();
|
||||
$new = publishLegalRule($this->f['issuer'], $next);
|
||||
expect($service->changed($frozen))->toBeTrue()->and($frozen['data']['suggested_code'])->toBe('1234.56')
|
||||
->and($published->fresh()->data['suggested_code'])->toBe('1234.56');
|
||||
$service->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $new->record_key, 'version' => 4,
|
||||
'action' => 'withdraw', 'reason' => 'Synthetic withdrawal without deleting original sources or applied decisions']);
|
||||
expect($find())->toBe([])->and(Storage::disk('local')->allFiles())->toHaveCount(1)
|
||||
->and([DB::table('budget_entries')->get()->toJson(), DB::table('invoices')->get()->toJson(), DB::table('stock_movements')->get()->toJson()])->toBe($before);
|
||||
});
|
||||
|
||||
test('buyer proposal freezes legal context and confirmation permits a reasoned deviation while changes require a current source', function () {
|
||||
$service = app(ImportLegalRules::class);
|
||||
$published = publishLegalRule($this->f['issuer'], $service->save($this->f['issuer'], legalRuleInput(), legalRuleFile()));
|
||||
$tariffs = app(ImportTariffCodes::class);
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'action' => 'propose', 'version' => 0, 'requisition_item_id' => $this->f['r']->items()->sole()->id,
|
||||
'code' => '1234.56', 'source_reference' => $published->data['official_reference'].' — '.$published->data['citation'], 'legal_rule_id' => $published->id,
|
||||
'legal_match_code' => '1234', 'legal_origin' => 'Synthetic A', 'legal_sector' => 'Synthetic sector', 'legal_date' => '2026-11-27',
|
||||
'reason' => 'Synthetic buyer selection of a documented suggestion'];
|
||||
$proposal = $tariffs->save($this->f['issuer'], $this->f['r'], $input);
|
||||
$confirmed = $tariffs->save($this->f['issuer'], $this->f['r'], ['operation_key' => (string) Str::uuid(), 'action' => 'confirm', 'version' => 1,
|
||||
'requisition_item_id' => $input['requisition_item_id'], 'code' => '1234.59', 'source_reference' => 'Synthetic technical classification reference',
|
||||
'reason' => 'Synthetic buyer explains the documented deviation from the suggested code']);
|
||||
expect($confirmed->data['deviation'])->toBeTrue()->and($confirmed->snapshot['legal_rule']['id'])->toBe($published->id)
|
||||
->and($confirmed->snapshot['calculations_activated'])->toBeFalse()->and($proposal->fresh()->state)->toBe('proposed');
|
||||
expect($tariffs->freezeForItems($this->f['issuer'], [$input['requisition_item_id']])[$input['requisition_item_id']]['legal_rule'])->toBe($confirmed->snapshot['legal_rule']);
|
||||
$tariffs->save($this->f['issuer'], $this->f['r'], [...$input, 'operation_key' => (string) Str::uuid(), 'version' => 2]);
|
||||
$draft = $service->save($this->f['issuer'], legalRuleInput(['record_key' => $published->record_key, 'version' => 2]));
|
||||
publishLegalRule($this->f['issuer'], $draft);
|
||||
expect(fn () => $tariffs->save($this->f['issuer'], $this->f['r'], ['operation_key' => (string) Str::uuid(), 'action' => 'confirm', 'version' => 3,
|
||||
'requisition_item_id' => $input['requisition_item_id'], 'code' => '1234.56', 'source_reference' => 'Synthetic source', 'reason' => 'Synthetic obsolete-source confirmation must fail']))->toThrow(HttpException::class);
|
||||
expect($tariffs->workspace($this->f['issuer'], $this->f['r'])['latest']->first()->legal_changed)->toBeTrue();
|
||||
});
|
||||
|
||||
test('legal management rejects stale operations foreign access revoked permissions and missing or altered original bytes', function () {
|
||||
$service = app(ImportLegalRules::class);
|
||||
$input = legalRuleInput();
|
||||
$draft = $service->save($this->f['issuer'], $input, legalRuleFile());
|
||||
expect(fn () => $service->save($this->f['issuer'], [...$input, 'title' => 'Changed title'], legalRuleFile()))->toThrow(HttpException::class);
|
||||
expect(fn () => $service->save($this->f['issuer'], legalRuleInput(['record_key' => $draft->record_key])))->toThrow(HttpException::class);
|
||||
$viewer = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'purchasing_role' => PurchasingRole::Procurement]);
|
||||
supplyGrant($viewer, ['procurement']);
|
||||
$this->actingAs($viewer);
|
||||
expect(fn () => publishLegalRule($viewer, $draft))->toThrow(HttpException::class);
|
||||
$foreign = receiptFixture();
|
||||
supplyGrant($foreign['issuer'], ['procurement', 'import_customs']);
|
||||
$this->actingAs($foreign['issuer']);
|
||||
expect(fn () => $service->source($foreign['issuer'], $foreign['r'], $draft->snapshot['source_id']))->toThrow(ModelNotFoundException::class);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$source = $service->source($this->f['issuer'], $this->f['r'], $draft->snapshot['source_id']);
|
||||
Storage::disk('local')->put($source->snapshot['evidence']['path'], 'altered');
|
||||
expect(fn () => publishLegalRule($this->f['issuer'], $draft))->toThrow(HttpException::class);
|
||||
DB::table('organization_memberships')->where('user_id', $this->f['issuer']->id)->delete();
|
||||
expect(fn () => $service->workspace($this->f['issuer'], $this->f['r']))->toThrow(HttpException::class);
|
||||
});
|
||||
|
||||
test('native legal forms keep sources private and allow source download and explicit human publication only', function () {
|
||||
$url = '/requisicoes/'.$this->f['r']->id.'/base-legal';
|
||||
$this->post($url, [...legalRuleInput(), 'file' => legalRuleFile()])->assertRedirect();
|
||||
$draft = SupplyRecord::query()->where('kind', 'import_legal_rule')->sole();
|
||||
$this->get($url)->assertOk()->assertHeader('Cache-Control', 'max-age=0, no-store, private');
|
||||
$source = app(ImportLegalRules::class)->source($this->f['issuer'], $this->f['r'], $draft->snapshot['source_id']);
|
||||
$download = $this->get($url.'/fontes/'.$source->id)->assertOk()->assertHeader('X-Content-Type-Options', 'nosniff');
|
||||
expect($download->getContent())->toBe(app(ImportEvidence::class)->bytes($source));
|
||||
$this->getJson($url.'?rules_page=0')->assertUnprocessable();
|
||||
config(['import-legal.qa_enabled' => false]);
|
||||
$this->get($url)->assertStatus(503);
|
||||
});
|
||||
|
||||
test('missing source alerts an already applied rule and changed source metadata requires a new original', function () {
|
||||
$service = app(ImportLegalRules::class);
|
||||
$draft = $service->save($this->f['issuer'], legalRuleInput(), legalRuleFile());
|
||||
$published = publishLegalRule($this->f['issuer'], $draft);
|
||||
$frozen = $service->freeze($published->id, '1234', 'Synthetic A', 'Synthetic sector', '2026-11-27');
|
||||
expect(fn () => $service->save($this->f['issuer'], legalRuleInput(['record_key' => $published->record_key, 'version' => 2,
|
||||
'official_reference' => 'Different synthetic source without its original'])))->toThrow(HttpException::class);
|
||||
$source = $service->source($this->f['issuer'], $this->f['r'], $frozen['source_id']);
|
||||
Storage::disk('local')->delete($source->snapshot['evidence']['path']);
|
||||
expect($service->changed($frozen))->toBeTrue();
|
||||
expect(fn () => $service->freeze($published->id, '1234', 'Synthetic A', 'Synthetic sector', '2026-11-27'))->toThrow(HttpException::class);
|
||||
});
|
||||
|
||||
test('an official source larger than a transactional attachment remains consultable without truncation', function () {
|
||||
$bytes = "%PDF-1.4\n".str_repeat('Synthetic legal publication page bytes ', 70000)."\n%%EOF";
|
||||
$service = app(ImportLegalRules::class);
|
||||
$draft = $service->save($this->f['issuer'], legalRuleInput(), UploadedFile::fake()->createWithContent('large-source.pdf', $bytes));
|
||||
$source = $service->source($this->f['issuer'], $this->f['r'], $draft->snapshot['source_id']);
|
||||
expect(strlen($bytes))->toBeGreaterThan(2097152)->and(app(ImportEvidence::class)->bytes($source))->toBe($bytes);
|
||||
expect(publishLegalRule($this->f['issuer'], $draft)->snapshot['source_sha256'])->toBe(hash('sha256', $bytes));
|
||||
});
|
||||
|
||||
test('a shared official source is independently consultable and reused without inventing a code or publishing a rule', function () {
|
||||
$service = app(ImportLegalRules::class);
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'action' => 'source',
|
||||
'official_reference' => 'Synthetic complete official journal; no rule or inferred rate',
|
||||
'reason' => 'Retain the synthetic official publication independently of its later use'];
|
||||
$source = $service->save($this->f['issuer'], $input, legalRuleFile());
|
||||
expect($service->save($this->f['issuer'], $input, legalRuleFile())->id)->toBe($source->id)
|
||||
->and($source->kind)->toBe('import_legal_source')->and($source->data['official_url'])->toBeNull()
|
||||
->and(SupplyRecord::query()->where('kind', 'import_legal_rule')->count())->toBe(0);
|
||||
$rule = $service->save($this->f['issuer'], legalRuleInput(['source_id' => $source->id,
|
||||
'official_reference' => $source->data['official_reference'], 'official_url' => null]));
|
||||
expect($rule->snapshot['source_id'])->toBe($source->id)->and(Storage::disk('local')->allFiles())->toHaveCount(1)
|
||||
->and($service->workspace($this->f['issuer'], $this->f['r'])['sources']->total())->toBe(1);
|
||||
$other = $service->save($this->f['issuer'], [...$input, 'operation_key' => (string) Str::uuid(), 'official_reference' => 'Another synthetic official source'], legalRuleFile());
|
||||
expect(fn () => $service->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $rule->record_key, 'version' => 1,
|
||||
'action' => 'publish', 'source_id' => $other->id, 'reason' => 'A publication decision cannot silently replace the prepared original']))->toThrow(HttpException::class);
|
||||
expect(publishLegalRule($this->f['issuer'], $rule)->snapshot['source_id'])->toBe($source->id);
|
||||
});
|
||||
|
||||
test('publishing a future period preserves the earlier applicable period without resurrecting an expired replacement', function () {
|
||||
$service = app(ImportLegalRules::class);
|
||||
$first = publishLegalRule($this->f['issuer'], $service->save($this->f['issuer'], legalRuleInput(), legalRuleFile()));
|
||||
$future = publishLegalRule($this->f['issuer'], $service->save($this->f['issuer'], legalRuleInput(['record_key' => $first->record_key, 'version' => 2,
|
||||
'valid_from' => '2027-01-01', 'valid_until' => '2027-06-30', 'suggested_code' => '1234.57'])));
|
||||
$find = fn ($date) => $service->suggestions($this->f['issuer'], $this->f['r'], '1234', 'Synthetic A', 'Synthetic sector', $date);
|
||||
expect($find('2026-11-27')[0]['id'])->toBe($first->id)->and($find('2027-01-01')[0]['id'])->toBe($future->id)
|
||||
->and($find('2027-07-01'))->toBe([])
|
||||
->and($service->freeze($first->id, '1234', 'Synthetic A', 'Synthetic sector', '2026-11-27')['id'])->toBe($first->id);
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Services\ImportBankSupport;
|
||||
use App\Services\ImportDossier;
|
||||
use App\Services\ImportLegalRules;
|
||||
use App\Services\ImportReadiness;
|
||||
use App\Services\InventoryLots;
|
||||
use App\Services\ReceiptWorkflow;
|
||||
use App\Services\SupplyPlanning;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
require_once __DIR__.'/../Support/ImportLegalQaFixture.php';
|
||||
require_once __DIR__.'/../Support/ImportBankQaFixture.php';
|
||||
|
||||
beforeEach(function () {
|
||||
config(['import-readiness.qa_enabled' => true, 'import-dossier.qa_enabled' => true, 'import-bank-support.qa_enabled' => true,
|
||||
'import-legal.qa_enabled' => true, 'import-tariffs.qa_enabled' => true]);
|
||||
Storage::fake('local');
|
||||
$this->withoutVite();
|
||||
$this->f = receiptFixture();
|
||||
supplyGrant($this->f['issuer'], ['procurement', 'import_prepare', 'import_customs']);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$this->import = app(SupplyPlanning::class)->save($this->f['issuer'], 'import', supplyInput([
|
||||
'purchase_order_id' => $this->f['order']->id, 'purpose' => 'internal', 'jurisdiction' => 'Synthetic readiness jurisdiction',
|
||||
'origin_country' => 'Synthetic A', 'dispatch_country' => 'Synthetic B', 'regime' => 'Synthetic regime',
|
||||
'expected_usable_on' => today()->subDay()->toDateString()]));
|
||||
});
|
||||
|
||||
test('current import alerts distinguish unknown requirements and the expected receipt from customs release without side effects', function () {
|
||||
$service = app(ImportReadiness::class);
|
||||
$before = [];
|
||||
foreach (['supply_records', 'audit_logs', 'budget_entries', 'stock_movements', 'invoices', 'workflow_notices'] as $table) {
|
||||
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
|
||||
}
|
||||
$workspace = $service->workspace($this->f['issuer'], $this->import);
|
||||
expect(array_column($workspace['alerts'], 'key'))->toContain('expected-due', 'classification-unknown', 'parties-unknown', 'bank-unknown')
|
||||
->and($workspace['complete'])->toBeTrue()->and($workspace['financialEffects'])->toBeFalse()->and($workspace['automaticNotifications'])->toBeFalse();
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
$planning = app(SupplyPlanning::class);
|
||||
$transit = $planning->save($this->f['issuer'], 'import', supplyInput(['evidence' => 'Synthetic transit', 'event_date' => today()->toDateString()], 'transit', $this->import));
|
||||
$arrived = $planning->save($this->f['issuer'], 'import', supplyInput(['evidence' => 'Synthetic arrival', 'event_date' => today()->toDateString()], 'arrive', $transit));
|
||||
expect(array_column($service->workspace($this->f['issuer'], $arrived)['alerts'], 'key'))->toContain('customs-pending');
|
||||
supplyGrant($this->f['receiver'], ['warehouse', 'import_customs', 'import_read']);
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$released = $planning->save($this->f['receiver'], 'import', supplyInput(['evidence' => 'Synthetic independent release', 'event_date' => today()->toDateString()], 'release', $arrived));
|
||||
$this->actingAs($this->f['issuer']);
|
||||
expect(array_column($service->workspace($this->f['issuer'], $released)['alerts'], 'key'))->toContain('expected-due')->not->toContain('customs-pending');
|
||||
$this->actingAs($this->f['receiver']);
|
||||
app(ReceiptWorkflow::class)->confirm($this->f['receiver'], $this->f['order'], receiptPayload($this->f, '1.000'));
|
||||
$this->actingAs($this->f['issuer']);
|
||||
expect(array_column($service->workspace($this->f['issuer'], $released)['alerts'], 'key'))->not->toContain('expected-due');
|
||||
});
|
||||
|
||||
test('document requirements come from the frozen rule and missing or altered evidence reopens the live alert', function () {
|
||||
$legal = app(ImportLegalRules::class);
|
||||
$draft = $legal->save($this->f['issuer'], importLegalQaInput(), importLegalQaFile());
|
||||
$published = $legal->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $draft->record_key, 'version' => 1,
|
||||
'action' => 'publish', 'reason' => 'Synthetic customs source publication for current alerts']);
|
||||
$frozen = $legal->freeze($published->id, '1234', 'Synthetic A', 'Synthetic sector', '2026-11-27');
|
||||
// Construct an issued-order fixture; no production order is rewritten.
|
||||
DB::table('purchase_orders')->where('id', $this->f['order']->id)->update(['snapshot' => json_encode([...$this->f['order']->snapshot,
|
||||
'import_tariffs' => [['record_id' => 999, 'item' => ['description' => 'Synthetic classified item'],
|
||||
'data' => ['requisition_id' => $this->f['r']->id], 'legal_rule' => $frozen]]], JSON_THROW_ON_ERROR)]);
|
||||
$service = app(ImportReadiness::class);
|
||||
expect(array_column($service->workspace($this->f['issuer'], $this->import)['alerts'], 'key'))->toContain('required-licence');
|
||||
$document = app(ImportDossier::class)->record($this->f['issuer'], $this->import, ['operation_key' => (string) Str::uuid(), 'type' => 'licence',
|
||||
'reference' => 'LICENCE-QA', 'issuer_reference' => 'Synthetic issuer', 'reason' => 'Synthetic licence for documentary readiness'],
|
||||
UploadedFile::fake()->createWithContent('licence.pdf', "%PDF-1.4\nSynthetic licence\n%%EOF"));
|
||||
expect(array_column($service->workspace($this->f['issuer'], $this->import)['alerts'], 'key'))->not->toContain('required-licence');
|
||||
Storage::disk('local')->put($document->snapshot['evidence']['path'], 'altered');
|
||||
expect(array_column($service->workspace($this->f['issuer'], $this->import)['alerts'], 'key'))->toContain('required-licence', 'document-'.$document->id);
|
||||
$legal->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $published->record_key, 'version' => 2,
|
||||
'action' => 'withdraw', 'reason' => 'Synthetic withdrawal alerts the existing decision without deleting it']);
|
||||
expect(array_column($service->workspace($this->f['issuer'], $this->import)['alerts'], 'key'))->toContain('legal-changed-999');
|
||||
});
|
||||
|
||||
test('bank pending alerts reuse the native report and disappear after dated documentary delivery', function () {
|
||||
$fixture = importBankQaFixture($this->f['issuer'], $this->import);
|
||||
$bank = app(ImportBankSupport::class);
|
||||
$first = $bank->save($this->f['issuer'], $this->import, $fixture['input']);
|
||||
$service = app(ImportReadiness::class);
|
||||
$bankAlerts = fn () => array_values(array_filter($service->workspace($this->f['issuer'], $this->import)['alerts'], fn ($alert) => $alert['category'] === 'Suporte bancário'));
|
||||
expect($bankAlerts())->not->toBeEmpty();
|
||||
$bank->save($this->f['issuer'], $this->import, [...$fixture['input'], 'operation_key' => (string) Str::uuid(),
|
||||
'record_key' => $first->record_key, 'version' => 1, 'submission_document_id' => $fixture['documents']['delivery']->id,
|
||||
'submitted_on' => today()->toDateString(), 'submission_basis' => 'Synthetic documentary delivery evidence']);
|
||||
expect($bankAlerts())->toBe([]);
|
||||
config(['import-bank-support.qa_enabled' => false]);
|
||||
$workspace = $service->workspace($this->f['issuer'], $this->import);
|
||||
expect($workspace['complete'])->toBeFalse()->and(array_column($workspace['alerts'], 'key'))->toContain('bank-unavailable');
|
||||
});
|
||||
|
||||
test('native follow-up revalidates current identity company context versions and private response headers', function () {
|
||||
$url = '/compras/importacoes/'.$this->import->id.'/acompanhamento';
|
||||
$this->get($url)->assertOk()->assertHeader('Cache-Control', 'max-age=0, no-store, private')
|
||||
->assertInertia(fn (Assert $page) => $page->component('supply/import-readiness')->where('automaticNotifications', false));
|
||||
$foreign = receiptFixture();
|
||||
supplyGrant($foreign['issuer'], ['procurement', 'import_read']);
|
||||
$this->actingAs($foreign['issuer'])->get($url)->assertNotFound();
|
||||
$this->actingAs($this->f['issuer']);
|
||||
DB::table('organization_memberships')->where('user_id', $this->f['issuer']->id)->delete();
|
||||
expect(fn () => app(ImportReadiness::class)->workspace($this->f['issuer'], $this->import))->toThrow(HttpException::class);
|
||||
});
|
||||
|
||||
test('accepted receipt in quarantine remains an availability alert until native independent quality release', function () {
|
||||
$planning = app(SupplyPlanning::class);
|
||||
$transit = $planning->save($this->f['issuer'], 'import', supplyInput(['evidence' => 'Synthetic transit', 'event_date' => today()->toDateString()], 'transit', $this->import));
|
||||
$arrived = $planning->save($this->f['issuer'], 'import', supplyInput(['evidence' => 'Synthetic arrival', 'event_date' => today()->toDateString()], 'arrive', $transit));
|
||||
supplyGrant($this->f['issuer'], ['inventory_lot_prepare']);
|
||||
$lots = app(InventoryLots::class);
|
||||
$setup = $lots->save($this->f['issuer'], supplyInput(['stock_item_id' => $this->f['stock']->id, 'warehouse_id' => $this->f['warehouse']->id,
|
||||
'requires_expiry' => false, 'minimum_remaining_days' => 0, 'lots' => [], 'quarantine_on_receipt' => true], 'prepare'));
|
||||
supplyGrant($this->f['receiver'], ['warehouse', 'import_customs', 'inventory_lot_review']);
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$lots->save($this->f['receiver'], supplyInput([], 'activate', $setup));
|
||||
$released = $planning->save($this->f['receiver'], 'import', supplyInput(['evidence' => 'Synthetic independent release', 'event_date' => today()->toDateString()], 'release', $arrived));
|
||||
$input = receiptPayload($this->f, '1.000');
|
||||
$input['items'][0]['lots'] = [['code' => 'QA-LOT', 'no_expiry' => true]];
|
||||
app(ReceiptWorkflow::class)->confirm($this->f['receiver'], $this->f['order'], $input);
|
||||
$lot = $lots->context($this->f['stock']->id, $this->f['warehouse']->id)['lots'][0];
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$alerts = app(ImportReadiness::class)->workspace($this->f['issuer'], $released)['alerts'];
|
||||
expect(array_column($alerts, 'key'))->toContain('stock-held-'.$lot['id'].'-'.$this->f['warehouse']->id);
|
||||
supplyGrant($this->f['otherReceiver'], ['warehouse', 'inventory_lot_release']);
|
||||
$this->actingAs($this->f['otherReceiver']);
|
||||
$lots->save($this->f['otherReceiver'], supplyInput(['lot_id' => $lot['id'], 'warehouse_id' => $this->f['warehouse']->id,
|
||||
'state_version' => $lot['state_version']], 'release', SupplyRecord::query()->findOrFail($lot['metadata_id'])));
|
||||
$this->actingAs($this->f['issuer']);
|
||||
expect(array_column(app(ImportReadiness::class)->workspace($this->f['issuer'], $released)['alerts'], 'key'))->not->toContain('stock-held-'.$lot['id'].'-'.$this->f['warehouse']->id);
|
||||
});
|
||||
@@ -31,6 +31,8 @@ use App\Models\User;
|
||||
use App\Models\Warehouse;
|
||||
use App\Services\AgreementOrderLimits;
|
||||
use App\Services\BudgetWorkflow;
|
||||
use App\Services\CapitalAssignments;
|
||||
use App\Services\CapitalRegister;
|
||||
use App\Services\CommonBudget;
|
||||
use App\Services\ComparisonPolicy;
|
||||
use App\Services\ConflictGuard;
|
||||
@@ -71,6 +73,67 @@ require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/BudgetDistributionSchema.php';
|
||||
|
||||
function nativeCapitalAssignment(object $test): array
|
||||
{
|
||||
config(['capital-register.qa_enabled' => true]);
|
||||
$test->actingAs($test->buyer);
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0, 'type' => 'project',
|
||||
'code' => 'PRJ-NATIVE-QA', 'name' => 'Projecto sintético da ordem', 'department_id' => $test->department->id,
|
||||
'equipment_id' => null, 'reference' => 'Documento sintético de investimento', 'state' => 'active', 'reason' => 'Cadastro estritamente sintético da ligação à ordem'];
|
||||
$source = app(CapitalRegister::class)->save($test->buyer, $input);
|
||||
// Extend the pre-approved synthetic fixture with a choice made while it was a draft.
|
||||
$test->r->update(['status' => 'draft']);
|
||||
$test->actingAs($test->owner);
|
||||
$assignment = app(CapitalAssignments::class)->save($test->owner, $test->r, ['operation_key' => (string) Str::uuid(),
|
||||
'version' => 0, 'item_id' => $test->item->id, 'capital_id' => $source->id, 'reason' => 'Destino documental escolhido pelo requisitante sintético']);
|
||||
$test->r->update(['status' => 'approved']);
|
||||
$test->actingAs($test->buyer);
|
||||
|
||||
return [$source, $assignment, $input];
|
||||
}
|
||||
|
||||
test('native order preserves the capital destination and print after the independent register is archived', function () {
|
||||
[$source, $assignment, $input] = nativeCapitalAssignment($this);
|
||||
$award = selectPurchaseAward($this);
|
||||
$order = issuePurchaseOrder($this, $award);
|
||||
expect($order->snapshot['capital_assignments'][$this->item->id]['id'])->toBe($assignment->id)
|
||||
->and($order->total_minor)->toBe($award->total_minor);
|
||||
app(CapitalRegister::class)->save($this->buyer, [...$input, 'operation_key' => (string) Str::uuid(),
|
||||
'record_key' => $source->record_key, 'version' => 1, 'name' => 'Nome posterior ao documento', 'state' => 'archived']);
|
||||
$this->get('/ordens/'.$order->id.'/imprimir')->assertOk()->assertSee('PRJ-NATIVE-QA')->assertSee('Projecto sintético da ordem')->assertDontSee('Nome posterior ao documento');
|
||||
expect($order->fresh()->snapshot['capital_assignments'][$this->item->id]['snapshot']['source']['version'])->toBe(1);
|
||||
$this->withoutVite();
|
||||
$this->get('/projectos-imobilizado?history='.$source->record_key)->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page->has('trace.orders.data', 1)->where('trace.orders.data.0.order_number', $order->number)->has('trace.receipts.data', 0));
|
||||
$receiver = User::factory()->create(['tenant_id' => $this->tenant->id, 'department_id' => $this->department->id, 'purchasing_role' => PurchasingRole::Warehouse]);
|
||||
$this->actingAs($receiver);
|
||||
$warehouse = Warehouse::query()->create(['tenant_id' => $this->tenant->id, 'created_by' => $receiver->id, 'code' => 'CAPITAL-QA', 'name' => 'Armazém sintético']);
|
||||
$stock = StockItem::query()->create(['tenant_id' => $this->tenant->id, 'created_by' => $receiver->id, 'code' => 'CAPITAL-QA', 'name' => 'Artigo sintético', 'unit' => 'un']);
|
||||
$receipt = app(ReceiptWorkflow::class)->confirm($receiver, $order, ['idempotency_key' => (string) Str::uuid(), 'delivery_note' => 'CAPITAL-NATIVE-RECEIPT',
|
||||
'received_on' => today()->toDateString(), 'warehouse_id' => $warehouse->id,
|
||||
'items' => [['purchase_order_item_id' => $order->items()->sole()->id, 'received_quantity' => '1.000', 'accepted_quantity' => '1.000', 'quality_status' => 'compliant', 'stock_item_id' => $stock->id]]]);
|
||||
$this->actingAs($this->buyer);
|
||||
$before = DB::table('stock_movements')->get()->toJson();
|
||||
$this->get('/projectos-imobilizado?history='.$source->record_key)->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page->has('trace.receipts.data', 1)->where('trace.receipts.data.0.receipt_id', $receipt->id)
|
||||
->where('trace.receipts.data.0.accepted_quantity', '1.000')->where('trace.receipts.data.0.returned_quantity', '0.000')->where('trace.receipts.data.0.reversed', false));
|
||||
expect(DB::table('stock_movements')->get()->toJson())->toBe($before);
|
||||
});
|
||||
|
||||
test('native partial order freezes the same explicit capital origin without changing its financial allocation', function () {
|
||||
if (! method_exists(BudgetControl::class, 'commitOrderParts')) {
|
||||
$this->markTestSkipped('Select the approved isolated-QA common source for native order parts.');
|
||||
}
|
||||
[, $assignment] = nativeCapitalAssignment($this);
|
||||
$award = nativeOrderPartsAward($this);
|
||||
$input = nativeOrderPartsInput($this, $award, '0.400', 0);
|
||||
$this->actingAs($this->buyer);
|
||||
$order = app(OrderPartsWorkflow::class)->issue($this->buyer, $input);
|
||||
expect($order->snapshot['capital_assignments'][$this->item->id]['id'])->toBe($assignment->id)
|
||||
->and($order->total_minor)->toBe(4000)->and(DB::table('budget_order_commands')->count())->toBe(1);
|
||||
$this->get('/ordens/'.$order->id.'/imprimir')->assertOk()->assertSee('PRJ-NATIVE-QA');
|
||||
});
|
||||
|
||||
test('confirmed import classifications freeze in a newly issued native order and survive later proposals', function () {
|
||||
config(['import-tariffs.qa_enabled' => true]);
|
||||
$tariffs = app(ImportTariffCodes::class);
|
||||
|
||||
Reference in New Issue
Block a user