@@ -1,9 +1,14 @@
|
||||
<?php
|
||||
|
||||
use App\Models\CostCenter;
|
||||
use App\Models\CriticalityLevel;
|
||||
use App\Models\Department;
|
||||
use App\Models\Equipment;
|
||||
use App\Models\User;
|
||||
use App\Models\WarehouseRequest;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\WarehouseFulfilment;
|
||||
use App\Services\WarehouseWorkdesk;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -20,6 +25,92 @@ beforeEach(function () {
|
||||
'lines' => [['stock_item_id' => $this->f['stock']->id, 'quantity' => '2.500', 'use' => 'internal', 'equipment_id' => null]]];
|
||||
});
|
||||
|
||||
test('warehouse list and detail agree when an owner no longer has preparation or department review authority', function () {
|
||||
$this->withoutVite();
|
||||
$this->postJson('/stock/requisicoes', $this->data)->assertRedirect();
|
||||
$record = WarehouseRequest::query()->sole();
|
||||
$actor = $this->f['issuer'];
|
||||
$desk = app(WarehouseWorkdesk::class);
|
||||
expect($desk->canView($actor, $record))->toBeTrue();
|
||||
DB::table('organization_memberships')->where('user_id', $actor->id)->update(['expires_at' => now()->subSecond()]);
|
||||
supplyGrant($actor, ['warehouse_request_deliver']);
|
||||
expect($desk->canView($actor, $record))->toBeFalse();
|
||||
$this->get('/stock/requisicoes/'.$record->id)->assertForbidden();
|
||||
expect($desk->visible($actor)->whereKey($record->id)->exists())->toBeFalse();
|
||||
$this->get('/stock/requisicoes')->assertOk()->assertInertia(fn (Assert $page) => $page->where('records.total', 0));
|
||||
supplyGrant($actor, ['warehouse_request_read']);
|
||||
expect($desk->canView($actor, $record))->toBeTrue();
|
||||
$this->get('/stock/requisicoes')->assertOk()->assertInertia(fn (Assert $page) => $page->where('records.total', 1));
|
||||
});
|
||||
|
||||
test('global warehouse search uses native references event state literal terms and pagination without effects', function () {
|
||||
$this->withoutVite();
|
||||
config(['procurement_search.warehouse_requests_metadata_enabled' => true]);
|
||||
$this->postJson('/stock/requisicoes', [...$this->data, 'destination' => 'GLOBAL-WAREHOUSE%_QA'])->assertRedirect();
|
||||
$record = WarehouseRequest::query()->sole();
|
||||
$this->postJson('/stock/requisicoes/'.$record->id.'/eventos', ['operation_key' => (string) Str::uuid(),
|
||||
'version' => app(WarehouseFulfilment::class)->progress($record)['version'], 'action' => 'submit',
|
||||
'reason' => 'Submissão sintética para conferir a projecção de pesquisa'])->assertRedirect();
|
||||
foreach (range(1, 16) as $index) {
|
||||
$this->postJson('/stock/requisicoes', [...$this->data, 'operation_key' => (string) Str::uuid(),
|
||||
'destination' => 'PAGE-WAREHOUSE-'.$index])->assertRedirect();
|
||||
}
|
||||
$name = $record->snapshot['requester']['name'];
|
||||
$this->f['issuer']->update(['name' => 'Current name changed after request']);
|
||||
$before = [];
|
||||
foreach (['warehouse_requests', 'warehouse_request_events', 'audit_logs', 'stock_movements', 'requisitions', 'budget_entries'] as $table) {
|
||||
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
|
||||
}
|
||||
$this->get('/compras/pesquisa?q=RA-'.$record->id)->assertOk()->assertHeader('Cache-Control', 'max-age=0, no-store, private')
|
||||
->assertViewHas('page', fn ($page) => $page['encryptHistory'] === true)->assertInertia(fn (Assert $page) => $page
|
||||
->where('warehouseRequestSearchAvailable', true)->where('groups.1.key', 'warehouse_requests')->where('groups.1.records.total', 1)
|
||||
->where('groups.1.records.data.0.title', 'RA-'.$record->id)->where('groups.1.records.data.0.detail', 'submitted')
|
||||
->where('groups.1.records.data.0.href', '/stock/requisicoes/'.$record->id)
|
||||
->missing('groups.1.records.data.0.snapshot')->missing('groups.1.records.data.0.destination'));
|
||||
$this->get('/compras/pesquisa?q='.urlencode('%_'))->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 1));
|
||||
$this->get('/compras/pesquisa?q='.urlencode($name))->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 17));
|
||||
$this->get('/compras/pesquisa?q=PAGE-WAREHOUSE&warehouse_requests_page=2')->assertInertia(fn (Assert $page) => $page
|
||||
->where('groups.1.records.total', 16)->where('groups.1.records.current_page', 2)->has('groups.1.records.data', 1));
|
||||
$this->get('/compras/pesquisa?q=PAGE-WAREHOUSE&warehouse_requests_page=0')->assertSessionHasErrors('warehouse_requests_page');
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
$this->get('/stock/requisicoes/'.$record->id)->assertOk();
|
||||
config(['procurement_search.warehouse_requests_metadata_enabled' => false]);
|
||||
$this->get('/compras/pesquisa?q=RA-'.$record->id)->assertInertia(fn (Assert $page) => $page
|
||||
->where('warehouseRequestSearchAvailable', false)->has('groups', 1));
|
||||
});
|
||||
|
||||
test('global warehouse search and native read predicate agree across departments companies and withdrawn authority', function () {
|
||||
$this->withoutVite();
|
||||
config(['procurement_search.warehouse_requests_metadata_enabled' => true]);
|
||||
$own = $this->f;
|
||||
$this->postJson('/stock/requisicoes', [...$this->data, 'destination' => 'GLOBAL-SCOPE-OWN'])->assertRedirect();
|
||||
$record = WarehouseRequest::query()->sole();
|
||||
$department = Department::query()->create(['tenant_id' => $own['tenant']->id, 'name' => 'Other synthetic department']);
|
||||
$centre = CostCenter::query()->create(['tenant_id' => $own['tenant']->id, 'department_id' => $department->id, 'code' => 'SCOPE-QA', 'name' => 'Other synthetic centre']);
|
||||
$otherOwner = User::factory()->create(['tenant_id' => $own['tenant']->id, 'department_id' => $department->id]);
|
||||
supplyGrant($otherOwner, ['warehouse_request_prepare']);
|
||||
$this->actingAs($otherOwner)->postJson('/stock/requisicoes', [...$this->data, 'operation_key' => (string) Str::uuid(),
|
||||
'cost_center_id' => $centre->id, 'destination' => 'GLOBAL-SCOPE-OTHER-DEPARTMENT'])->assertRedirect();
|
||||
$foreign = receiptFixture();
|
||||
supplyGrant($foreign['issuer'], ['warehouse_request_prepare']);
|
||||
$this->actingAs($foreign['issuer'])->postJson('/stock/requisicoes', [...$this->data, 'operation_key' => (string) Str::uuid(),
|
||||
'warehouse_id' => $foreign['warehouse']->id, 'cost_center_id' => $foreign['r']->cost_center_id, 'destination' => 'GLOBAL-SCOPE-OTHER-COMPANY',
|
||||
'lines' => [['stock_item_id' => $foreign['stock']->id, 'quantity' => '1.000', 'use' => 'internal', 'equipment_id' => null]]])->assertRedirect();
|
||||
$this->actingAs($own['issuer'])->get('/compras/pesquisa?q=GLOBAL-SCOPE')->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 1));
|
||||
$reviewer = User::factory()->create(['tenant_id' => $own['tenant']->id, 'department_id' => $own['department']->id]);
|
||||
supplyGrant($reviewer, ['warehouse_request_review']);
|
||||
$this->actingAs($reviewer)->get('/compras/pesquisa?q=GLOBAL-SCOPE')->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 1));
|
||||
supplyGrant($reviewer, ['warehouse_request_read']);
|
||||
$this->get('/compras/pesquisa?q=GLOBAL-SCOPE')->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 2));
|
||||
$this->actingAs($own['issuer']);
|
||||
DB::table('organization_memberships')->where('user_id', $own['issuer']->id)->update(['expires_at' => now()->subSecond()]);
|
||||
supplyGrant($own['issuer'], ['warehouse_request_deliver']);
|
||||
$this->get('/compras/pesquisa?q=GLOBAL-SCOPE')->assertInertia(fn (Assert $page) => $page->where('groups.1.records.total', 0));
|
||||
expect(app(WarehouseWorkdesk::class)->canView($own['issuer'], $record))->toBeFalse();
|
||||
});
|
||||
|
||||
test('warehouse draft freezes catalogue and destination once without stock budget or purchase effects', function () {
|
||||
$moves = DB::table('stock_movements')->count();
|
||||
$purchases = DB::table('requisitions')->count();
|
||||
|
||||
Reference in New Issue
Block a user