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

This commit is contained in:
2026-11-28 07:11:35 +02:00
parent d58b75c87a
commit eb32c74c56
202 changed files with 17463 additions and 1526 deletions
+77
View File
@@ -8,11 +8,13 @@ use App\Models\GoodsReceipt;
use App\Models\Invoice;
use App\Models\Supplier;
use App\Models\User;
use App\Services\SupplyPlanning;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Inertia\Testing\AssertableInertia as Assert;
require_once __DIR__.'/../Support/ReceiptFixture.php';
require_once __DIR__.'/../Support/SupplyFixture.php';
beforeEach(function () {
// The new page is built privately; HTTP scope tests must not require publishing it to the pilot.
@@ -21,6 +23,81 @@ beforeEach(function () {
$this->actingAs($this->f['issuer']);
});
test('global supply search returns only current native agreement and contract references with no private payload or writes', function () {
config(['procurement_search.supply_metadata_enabled' => true, 'agreement_order_limits.qa_enabled' => true]);
supplyGrant($this->f['issuer'], ['supply_prepare']);
$planning = app(SupplyPlanning::class);
$agreement = $planning->save($this->f['issuer'], 'agreement', supplyInput([
'stock_item_id' => $this->f['stock']->id, 'warehouse_id' => $this->f['warehouse']->id,
'supplier_id' => $this->f['order']->supplier_id, 'habitual' => false, 'valid_from' => today()->toDateString(),
'valid_until' => today()->addYear()->toDateString(), 'origin' => 'local', 'currency' => 'MZN',
'price_minor' => 10000, 'lead_days' => 4, 'reference' => 'SEARCH-AGREEMENT-OLD']));
$current = $planning->save($this->f['issuer'], 'agreement', supplyInput([...$agreement->data,
'reference' => 'SEARCH-AGREEMENT-NEW'], 'save', $agreement));
$contract = $planning->save($this->f['issuer'], 'contract', supplyInput([
'supplier_id' => $this->f['order']->supplier_id, 'reference' => 'SEARCH-CONTRACT', 'currency' => 'MZN',
'valid_from' => today()->toDateString(), 'valid_until' => today()->addYear()->toDateString(),
'periodicity_days' => 30, 'order_limit_amount' => '100.00', 'lead_days' => 3]));
$supplierName = $contract->snapshot['supplier']['name'];
Supplier::query()->findOrFail($this->f['order']->supplier_id)->update(['name' => 'Later supplier name, outside original reference']);
$before = [];
foreach (['supply_records', 'audit_logs', 'requisitions', 'purchase_orders', 'invoices', 'stock_movements'] as $table) {
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
}
$this->get('/compras/pesquisa?q=SEARCH-')->assertOk()->assertViewHas('page', fn ($page) => $page['encryptHistory'] === true)->assertInertia(fn (Assert $page) => $page
->where('supplySearchAvailable', true)->has('groups', 3)
->where('groups.1.records.total', 1)->where('groups.1.records.data.0.id', $current->id)
->where('groups.1.records.data.0.title', 'SEARCH-AGREEMENT-NEW · v2')
->where('groups.1.records.data.0.href', '/compras/fornecimento?view=agreements&record_id='.$current->id.'#supply-record-'.$current->id)
->where('groups.2.records.data.0.id', $contract->id)->missing('groups.2.records.data.0.data')
->missing('groups.2.records.data.0.price_minor')->missing('groups.2.records.data.0.snapshot'));
$this->get('/compras/pesquisa?q=SEARCH-AGREEMENT-OLD')->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 0));
$this->get('/compras/pesquisa?q='.urlencode($supplierName))->assertInertia(fn (Assert $page) => $page
->where('groups.1.records.total', 1)->where('groups.2.records.total', 1));
foreach ($before as $table => $rows) {
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
}
$this->get('/compras/fornecimento?view=agreements&record_id='.$current->id)->assertOk();
$this->get('/compras/fornecimento?view=contracts&record_id='.$contract->id)->assertOk();
config(['procurement_search.supply_metadata_enabled' => false]);
$this->get('/compras/pesquisa?q=SEARCH-')->assertInertia(fn (Assert $page) => $page->where('supplySearchAvailable', false)->has('groups', 1));
});
test('supply search preserves native isolation literal matching pagination and current access', function () {
config(['procurement_search.supply_metadata_enabled' => true]);
$own = $this->f;
supplyGrant($own['issuer'], ['supply_read', 'supply_prepare']);
$planning = app(SupplyPlanning::class);
$input = ['stock_item_id' => $own['stock']->id, 'warehouse_id' => $own['warehouse']->id,
'supplier_id' => $own['order']->supplier_id, 'habitual' => false, 'valid_from' => today()->toDateString(),
'valid_until' => today()->addYear()->toDateString(), 'origin' => 'local', 'currency' => 'MZN', 'price_minor' => 10000, 'lead_days' => 4];
foreach (range(1, 17) as $index) {
$planning->save($own['issuer'], 'agreement', supplyInput([...$input, 'reference' => 'SUPPLY-PAGE-'.$index]));
}
$literal = $planning->save($own['issuer'], 'agreement', supplyInput([...$input, 'reference' => 'LITERAL%_SUPPLY']));
$foreign = receiptFixture();
supplyGrant($foreign['issuer'], ['supply_prepare']);
$this->actingAs($foreign['issuer']);
$planning->save($foreign['issuer'], 'agreement', supplyInput([...$input,
'stock_item_id' => $foreign['stock']->id, 'warehouse_id' => $foreign['warehouse']->id,
'supplier_id' => $foreign['order']->supplier_id, 'reference' => 'SUPPLY-PAGE-FOREIGN']));
$this->actingAs($own['issuer'])->get('/compras/pesquisa?q=SUPPLY-PAGE&agreements_page=2')->assertOk()
->assertInertia(fn (Assert $page) => $page->has('groups', 2)->where('groups.1.records.total', 17)
->where('groups.1.records.current_page', 2)->has('groups.1.records.data', 2));
$this->get('/compras/pesquisa?q='.urlencode('%_'))->assertInertia(fn (Assert $page) => $page
->where('groups.1.records.total', 1)->where('groups.1.records.data.0.id', $literal->id));
$this->get('/compras/pesquisa?q=SUPPLY-PAGE&agreements_page=0')->assertSessionHasErrors('agreements_page');
$this->get('/compras/pesquisa?q=SUPPLY-PAGE&contracts_page=0')->assertSessionHasErrors('contracts_page');
$requester = User::factory()->create(['tenant_id' => $own['tenant']->id, 'department_id' => $own['department']->id,
'purchasing_role' => PurchasingRole::Configured]);
supplyGrant($requester, ['requester']);
$this->actingAs($requester)->get('/compras/pesquisa?q=SUPPLY-PAGE')->assertOk()->assertInertia(fn (Assert $page) => $page
->where('supplySearchAvailable', false)->has('groups', 1));
$this->actingAs($own['issuer']);
DB::table('organization_memberships')->where('user_id', $own['issuer']->id)->update(['expires_at' => now()->subSecond()]);
$this->get('/compras/pesquisa?q=SUPPLY-PAGE')->assertForbidden();
});
test('process search combines native modules without exposing financial or contact data or writing records', function () {
$this->f['r']->update(['number' => 'QA-NEED-001', 'justification' => 'Necessidade sintética de ensaio global.']);
$supplier = Supplier::query()->findOrFail($this->f['order']->supplier_id);