@@ -26,6 +26,80 @@ beforeEach(function () {
|
||||
$this->actingAs($this->admin);
|
||||
});
|
||||
|
||||
test('operational order search retains literal matching pagination and opens the selected native source beyond the first page', function () {
|
||||
config(['operational-orders.qa_enabled' => true]);
|
||||
$service = app(OperationalOrders::class);
|
||||
$service->configure($this->admin, $this->policy);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$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, 'reference' => 'OP-FOUND-OLD']);
|
||||
foreach (range(1, 17) as $index) {
|
||||
$service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(), 'reference' => 'OP-PAGE-'.$index]);
|
||||
}
|
||||
$literal = $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(), 'reference' => 'OP%_LITERAL']);
|
||||
$sourceRows = SupplyRecord::query()->where('kind', 'op_order')->orderBy('id')->get()->toJson();
|
||||
$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['operationalOrderSearchAvailable'])->toBeTrue();
|
||||
|
||||
return collect($props['groups'])->firstWhere('key', 'operational_orders')['records'];
|
||||
};
|
||||
$page = $read('q=OP-PAGE-');
|
||||
expect($page['total'])->toBe(17)->and($page['data'])->toHaveCount(15)
|
||||
->and($page['next_page_url'])->toContain('q=OP-PAGE-', 'operational_orders_page=2');
|
||||
expect($read('q=OP-PAGE-&operational_orders_page=2')['data'])->toHaveCount(2);
|
||||
$match = $read('q='.urlencode('%_'));
|
||||
expect($match['total'])->toBe(1)->and($match['data'][0]['id'])->toBe($literal->id)
|
||||
->and($match['data'][0]['detail'])->toBe('recorded')->and($match['data'][0]['title'])->toContain('Produção OP%_LITERAL', 'v1')
|
||||
->and(array_keys($match['data'][0]))->toBe(['id', 'title', 'detail', 'href']);
|
||||
$oldMatch = $read('q=OP-FOUND-OLD')['data'][0];
|
||||
expect($oldMatch['href'])->toBe('/ordens-operacionais?order_id='.$old->id.'#op-order-'.$old->id);
|
||||
$this->get($oldMatch['href'])->assertOk()->assertInertia(fn (Assert $page) => $page->has('orders.data', 1)
|
||||
->where('orders.data.0.id', $old->id)->where('selectedOrderId', $old->id));
|
||||
$this->get('/ordens-operacionais?order_id='.$old->id.'&page=999')->assertOk()->assertInertia(fn (Assert $page) => $page
|
||||
->where('orders.current_page', 1)->has('orders.data', 1)->where('orders.data.0.id', $old->id));
|
||||
$this->get('/ordens-operacionais')->assertOk()->assertInertia(fn (Assert $page) => $page->has('orders.data', 15)->where('selectedOrderId', null));
|
||||
$this->getJson('/compras/pesquisa?q=OP&operational_orders_page=0')->assertUnprocessable();
|
||||
$this->getJson('/ordens-operacionais?order_id=0')->assertUnprocessable();
|
||||
expect(SupplyRecord::query()->where('kind', 'op_order')->orderBy('id')->get()->toJson())->toBe($sourceRows);
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
});
|
||||
|
||||
test('operational order search and direct source selection retain native departmental tenant and current capability boundaries', function () {
|
||||
config(['operational-orders.qa_enabled' => true]);
|
||||
$service = app(OperationalOrders::class);
|
||||
$service->configure($this->admin, $this->policy);
|
||||
supplyGrant($this->f['issuer'], ['procurement']);
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$own = $service->save($this->f['issuer'], $this->input);
|
||||
$department = Department::query()->create(['tenant_id' => $this->f['tenant']->id, 'code' => 'OP-OTHER', 'name' => 'Outro departamento sintético']);
|
||||
$other = $service->save($this->f['issuer'], [...$this->input, 'operation_key' => (string) Str::uuid(), 'department_id' => $department->id, 'reference' => 'OP-OTHER-SECRET']);
|
||||
$viewer = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id]);
|
||||
supplyGrant($viewer, ['production_order_prepare']);
|
||||
$this->actingAs($viewer);
|
||||
expect($service->searchQuery($viewer)?->pluck('id')->all())->toBe([$own->id]);
|
||||
$this->get('/compras/pesquisa?q=OP-OTHER-SECRET')->assertOk()->assertViewHas('page', fn (array $page) => collect($page['props']['groups'])->firstWhere('key', 'operational_orders')['records']['total'] === 0);
|
||||
$this->get('/ordens-operacionais?order_id='.$other->id)->assertNotFound();
|
||||
$this->get('/ordens-operacionais?order_id='.$own->id)->assertOk();
|
||||
DB::table('organization_profiles')->whereIn('id', DB::table('organization_memberships')->where('user_id', $viewer->id)->pluck('profile_id'))
|
||||
->update(['permissions' => json_encode(['finance'])]);
|
||||
$this->get('/compras/pesquisa?q=OP')->assertInertia(fn (Assert $page) => $page->where('operationalOrderSearchAvailable', false)
|
||||
->where('groups', fn ($groups) => ! collect($groups)->contains('key', 'operational_orders')));
|
||||
$this->get('/ordens-operacionais?order_id='.$own->id)->assertForbidden();
|
||||
$foreign = receiptFixture();
|
||||
$this->actingAs($foreign['issuer']);
|
||||
expect($service->searchQuery($foreign['issuer'])?->count())->toBe(0)->and($service->searchQuery($this->f['issuer']))->toBeNull();
|
||||
$this->get('/ordens-operacionais?order_id='.$own->id)->assertNotFound();
|
||||
config(['operational-orders.qa_enabled' => false]);
|
||||
expect($service->searchQuery($foreign['issuer']))->toBeNull();
|
||||
});
|
||||
|
||||
test('operational register requires explicit origin mode preserves sources and has no financial or stock effects', function () {
|
||||
$this->get('/ordens-operacionais')->assertStatus(503);
|
||||
config(['operational-orders.qa_enabled' => true]);
|
||||
|
||||
Reference in New Issue
Block a user