commit compras1 2911
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-29 05:28:30 +02:00
parent 1ddabbbdcc
commit 448948a487
137 changed files with 9481 additions and 1926 deletions
+68
View File
@@ -1,8 +1,10 @@
<?php
use App\Models\CriticalityLevel;
use App\Models\Department;
use App\Models\Equipment;
use App\Models\SupplyRecord;
use App\Models\User;
use App\Services\CapitalAssignments;
use App\Services\CapitalRegister;
use Illuminate\Database\Eloquent\ModelNotFoundException;
@@ -27,6 +29,72 @@ beforeEach(function () {
'reason' => 'Preparação de referência sintética para testes de compras'];
});
test('capital search returns current metadata literal matches pagination and native history links without business writes', 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();
}
$old = $service->save($this->f['issuer'], [...$this->input, 'name' => 'OLD-CAPITAL-SEARCH']);
$current = $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(),
'record_key' => $old->record_key, 'version' => 1, 'name' => 'NEW-CAPITAL%_SEARCH', 'state' => 'archived']);
$read = function (string $query) {
$response = $this->get('/compras/pesquisa?'.$query)->assertOk()
->assertHeader('Cache-Control', 'max-age=0, no-store, private');
$props = $response->viewData('page')['props'];
expect($props['capitalSearchAvailable'])->toBeTrue();
expect($props['capitalRegisterAvailable'])->toBeTrue();
return collect($props['groups'])->firstWhere('key', 'capital')['records'];
};
expect($read('q=OLD-CAPITAL-SEARCH')['total'])->toBe(0);
$literal = $read('q='.urlencode('%_'));
expect($literal['total'])->toBe(1)->and($literal['data'][0]['id'])->toBe($current->id)
->and($literal['data'][0]['detail'])->toBe('archived')
->and($literal['data'][0]['title'])->toContain('NEW-CAPITAL%_SEARCH', 'v2')
->and(array_keys($literal['data'][0]))->toBe(['id', 'title', 'detail', 'href'])
->and($literal['data'][0]['href'])->toBe('/projectos-imobilizado?history='.$old->record_key);
$this->get($literal['data'][0]['href'])->assertOk()->assertInertia(fn (Assert $page) => $page->has('history.data', 2));
foreach (range(1, 17) as $index) {
$service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(), 'code' => 'CAP-PAGE-'.$index]);
}
$firstPage = $read('q=CAP-PAGE-');
expect($firstPage['total'])->toBe(17)->and($firstPage['data'])->toHaveCount(15)
->and($firstPage['next_page_url'])->toContain('q=CAP-PAGE-', 'capital_page=2');
expect($read('q=CAP-PAGE-&capital_page=2')['data'])->toHaveCount(2);
$asset = $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(), 'code' => 'CAP-ASSET', 'type' => 'asset']);
expect($read('q=CAP-ASSET')['data'][0]['title'])->toContain('Imobilizado CAP-ASSET');
foreach ($before as $table => $rows) {
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
}
$this->getJson('/compras/pesquisa?q=CAP&capital_page=0')->assertUnprocessable();
});
test('capital search retains tenant departmental permission and QA boundaries', function () {
$service = app(CapitalRegister::class);
$own = $this->f;
$service->save($own['issuer'], $this->input);
$foreign = receiptFixture();
$this->actingAs($foreign['issuer']);
expect($service->searchQuery($foreign['issuer'])?->count())->toBe(0)
->and($service->searchQuery($own['issuer']))->toBeNull();
$this->actingAs($own['issuer']);
$department = Department::query()->create(['tenant_id' => $own['tenant']->id, 'code' => 'OTHER-CAP', 'name' => 'Outro departamento QA']);
$service->save($own['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(), 'code' => 'CAP-OTHER', 'department_id' => $department->id]);
$head = User::factory()->create(['tenant_id' => $own['tenant']->id, 'department_id' => $own['department']->id]);
supplyGrant($head, ['department_head']);
$this->actingAs($head);
expect($service->searchQuery($head)?->count())->toBe(1);
$this->get('/compras/pesquisa?q=CAP-OTHER')->assertOk()->assertViewHas('page', fn (array $page) => collect($page['props']['groups'])->firstWhere('key', 'capital')['records']['total'] === 0);
DB::table('organization_profiles')->whereIn('id', DB::table('organization_memberships')->where('user_id', $head->id)->pluck('profile_id'))
->update(['permissions' => json_encode(['requester'])]);
$this->get('/compras/pesquisa?q=PRJ')->assertInertia(fn (Assert $page) => $page->where('capitalSearchAvailable', false)->where('capitalRegisterAvailable', false)
->where('groups', fn ($groups) => ! collect($groups)->contains('key', 'capital')));
config(['capital-register.qa_enabled' => false]);
supplyGrant($own['issuer'], ['procurement']);
$this->actingAs($own['issuer'])->get('/compras/pesquisa?q=PRJ')->assertInertia(fn (Assert $page) => $page->where('capitalSearchAvailable', false));
});
test('own project register versions preserves identity and replay without financial or stock effects', function () {
$service = app(CapitalRegister::class);
$before = [];