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

This commit is contained in:
2026-11-28 15:45:52 +02:00
parent eb32c74c56
commit 060c119ba1
92 changed files with 4936 additions and 43 deletions
@@ -28,6 +28,13 @@ function render(
context = 'finance',
canCorrect = true,
sourceId = 3,
canAuthoriseRelease = false,
release: {
id: number;
authorised_by: number;
authorised_at: string;
reason: string;
} | null = null,
) {
return renderToStaticMarkup(
<App
@@ -51,6 +58,8 @@ function render(
organizationAccess: { permissions: ['finance'] },
history: [{ ...declaration, id: sourceId }],
canCorrect,
canAuthoriseRelease,
release,
declarations: {
data: [],
prev_page_url: null,
@@ -63,6 +72,42 @@ function render(
/>,
);
}
test('direction release preparation requires explicit capability and never submits on recovery', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key ===
`${identity}:correction:3:${declaration.declared_at}:false:release:data`
? {
reason: 'DIRECTION-RELEASE-DRAFT',
operation_key: 'synthetic-operation',
}
: undefined,
);
const post = vi.spyOn(router, 'post');
const html = render(true, 7, 4, 'finance', false, 3, true);
expect(html).toContain('DIRECTION-RELEASE-DRAFT');
expect(html).toContain('Autorizar levantamento');
expect(html).toContain('data-preparation-dirty="true"');
expect(render(true, 8, 4, 'finance', false, 3, true)).not.toContain(
'DIRECTION-RELEASE-DRAFT',
);
expect(render(true, 7, 4, 'finance', false, 3, false)).not.toContain(
'Autorizar levantamento',
);
expect(post).not.toHaveBeenCalled();
});
test('released declaration retains its history and shows the direction decision', () => {
const html = render(true, 7, 4, 'finance', false, 3, false, {
id: 1,
authorised_by: 9,
authorised_at: '2026-11-28T09:00:00Z',
reason: 'DIRECTION-AUTHORISED-QA',
});
expect(html).toContain('Impedimento levantado pela direcção');
expect(html).toContain('Original synthetic conflict');
expect(html).toContain('DIRECTION-AUTHORISED-QA');
expect(html).not.toContain('Autorizar levantamento</button>');
});
test('personal declaration preparation remains private to its actor company and context without submitting', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:new:data`
+37 -1
View File
@@ -3,7 +3,12 @@ import { renderToStaticMarkup } from 'react-dom/server';
import { expect, test } from 'vitest';
import Legal from '../../resources/js/pages/supply/import-legal';
function renderLegal(canManage: boolean, withRule = true, withCharges = false) {
function renderLegal(
canManage: boolean,
withRule = true,
withCharges = false,
withReference = false,
) {
const data = {
title: '<script>synthetic rule</script>',
official_reference: 'Synthetic official edition',
@@ -58,6 +63,25 @@ function renderLegal(canManage: boolean, withRule = true, withCharges = false) {
encryptHistory: true,
props: {
errors: {},
referenceDrafts: withReference
? [
{
source_id: 8,
code: '3506.91.20',
description:
'Silicone para selagem de painéis solares',
rate_percent: '20',
title: 'Taxa geral documental',
official_reference: 'Lei 8/2025',
official_url: null,
citation: 'Página 2180-(4)',
valid_from: '2026-01-01',
obligations:
'Conferir o exemplar e o regime aplicável',
charges: [],
},
]
: [],
requisition: { id: 1, number: 'QA' },
rules: page,
history: page,
@@ -78,6 +102,18 @@ function renderLegal(canManage: boolean, withRule = true, withCharges = false) {
);
}
test('official reference preparation is explicit and only available to the customs preparer', () => {
const allowed = renderLegal(true, false, false, true);
expect(allowed).toContain('Preparar a partir do exemplar oficial');
expect(allowed).toContain('3506.91.20');
expect(allowed).toContain('taxa geral 20%');
expect(allowed).toContain('não é uma pauta consolidada');
expect(allowed).toContain('não substituir');
const reader = renderLegal(false, false, false, true);
expect(reader).not.toContain('Preparar a partir do exemplar oficial');
expect(reader).not.toContain('Silicone para selagem');
});
test('legal consultation escapes titles preserves periods and offers verified-source downloads without management controls', () => {
const html = renderLegal(false);
expect(html).toContain('&lt;script&gt;synthetic rule&lt;/script&gt;');
+142
View File
@@ -0,0 +1,142 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import OperationalOrders from '@/pages/requisitions/operational-orders';
import Summary from '@/components/operational-order-summary';
import { procurementNavigation } from '@/lib/procurement-navigation';
afterEach(() => vi.restoreAllMocks());
const source = {
id: 5,
version: 1,
created_at: '2026-11-28T10:00:00Z',
reason: 'Synthetic source',
data: {
type: 'production',
reference: 'SOURCE-ORDER-QA',
utilisation_location: 'Synthetic line',
description: '<script>private-test</script>',
department_id: 1,
},
snapshot: {
author: { name: 'Synthetic procurement' },
department: { name: 'Synthetic department' },
policy: { data: { mode: 'procurement' } },
},
};
function render(
actor = 7,
canConfigure = true,
allowedTypes = ['production', 'maintenance'],
linked = false,
) {
return renderToStaticMarkup(
<App
initialComponent={OperationalOrders}
initialPage={{
component: 'requisitions/operational-orders',
url: '/ordens-operacionais',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: {
user: {
id: actor,
tenant_id: 4,
name: 'Synthetic actor',
},
},
workContext: { active: 'procurement.internal' },
organizationAccess: {
permissions: ['procurement', 'requester'],
},
policy: {
id: 1,
version: 1,
data: { mode: 'procurement' },
},
canConfigure,
allowedTypes,
departments: [{ id: 1, name: 'Synthetic department' }],
orders: {
data: [source],
prev_page_url: null,
next_page_url: null,
},
requisition: linked
? { id: 3, number: 'REQ-QA', status: 'draft' }
: null,
items: linked
? [{ id: 8, description: 'Synthetic item' }]
: [],
links: [],
canLink: linked,
},
}}
/>,
);
}
test('order preparation restores only its actor context and policy without automatic creation', () => {
const identity =
'procurement-preparations:4:7:procurement.internal:procurement,requester:operational-orders:1:1:production,maintenance:true:0:false';
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:new:form:data`
? {
type: 'production',
reference: 'RESTORED-ORDER-DRAFT',
department_id: '1',
utilisation_location: 'Synthetic location',
description: 'Synthetic pending work',
reason: 'Synthetic pending reason',
policy_version: '1',
operation_key: '36cb64ea-0867-4be4-90ea-c0e114ec07b1',
}
: undefined,
);
const post = vi.spyOn(router, 'post');
const html = render();
expect(html).toContain('RESTORED-ORDER-DRAFT');
expect(html).toContain('data-preparation-dirty="true"');
expect(render(8)).not.toContain('RESTORED-ORDER-DRAFT');
expect(post).not.toHaveBeenCalled();
});
test('native capabilities control configuration creation and request linking independently', () => {
const html = render(7, false, [], true);
expect(html).not.toContain('Guardar origem das novas ordens');
expect(html).not.toContain('>Registar ordem</button>');
expect(html).toContain('Ligar ordem à linha');
expect(html).toContain('SOURCE-ORDER-QA');
expect(html).not.toContain('<script>private-test</script>');
});
test('order origin summary preserves the source responsibility and renders no empty section', () => {
expect(renderToStaticMarkup(<Summary />)).toBe('');
const html = renderToStaticMarkup(
<Summary
records={{
8: {
id: 9,
snapshot: {
item: { description: 'Synthetic item' },
source,
},
},
}}
/>,
);
expect(html).toContain('SOURCE-ORDER-QA');
expect(html).toContain('Synthetic procurement');
expect(html).toContain('Registada pelo procurement');
expect(html).not.toContain('<script>private-test</script>');
});
test('operational order navigation requires server readiness and an applicable capability', () => {
const has = (permissions: string[], ready: boolean) =>
procurementNavigation(permissions, false, undefined, false, ready)
.flatMap((group) => group.entries)
.some((entry) => entry.id === 'operational_orders');
expect(has(['production_order_prepare'], true)).toBe(true);
expect(has(['maintenance_order_prepare'], true)).toBe(true);
expect(has(['procurement'], false)).toBe(false);
expect(has(['finance'], true)).toBe(false);
});
+67
View File
@@ -0,0 +1,67 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import PrivateAudit from '@/pages/audit/private';
import { procurementNavigation } from '@/lib/procurement-navigation';
afterEach(() => vi.restoreAllMocks());
test('private audit preparation shows only granted families and does not submit on opening', () => {
const post = vi.spyOn(router, 'post');
const html = renderToStaticMarkup(
<App
initialComponent={PrivateAudit}
initialPage={{
component: 'audit/private',
url: '/auditoria/privada',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: {
user: {
id: 7,
tenant_id: 4,
name: 'Synthetic auditor',
},
},
organizationAccess: {
permissions: ['audit_private_stock_read'],
},
families: [{ key: 'stock', label: 'Stock autorizado' }],
exports: {
data: [],
prev_page_url: null,
next_page_url: null,
},
},
}}
/>,
);
expect(html).toContain('Stock autorizado');
expect(html).not.toContain('value="finance"');
expect(html).toContain('disabled');
expect(post).not.toHaveBeenCalled();
});
test('private audit navigation needs both QA availability and dedicated family authority', () => {
const paths = (permissions: string[], available: boolean) =>
procurementNavigation(
permissions,
false,
undefined,
false,
false,
available,
).flatMap((group) => group.entries.map((entry) => entry.path));
expect(paths(['audit_private_stock_read'], true)).toContain(
'/auditoria/privada',
);
expect(paths(['audit_private_stock_read'], false)).not.toContain(
'/auditoria/privada',
);
for (const permission of ['audit_metadata_read', 'finance', 'admin']) {
expect(paths([permission], true)).not.toContain('/auditoria/privada');
}
});
+16 -1
View File
@@ -30,7 +30,22 @@ function render(
component: 'test',
url: '/teste',
version: null,
props: { errors: {}, ...props },
props: {
errors: {},
auth: {
user: {
id: 12,
tenant_id: 4,
name: 'Synthetic banking reader',
},
},
workContext: { active: 'procurement.internal' },
organizationAccess: {
active: true,
permissions: props.canManage ? ['finance'] : ['admin'],
},
...props,
},
clearHistory: false,
encryptHistory: true,
} satisfies Page;
@@ -0,0 +1,153 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import UrgentStock from '@/pages/requisitions/urgent-stock';
import Summary from '@/components/urgent-quotation-summary';
import { ComparisonPolicySummary } from '@/components/comparison-policy-summary';
afterEach(() => vi.restoreAllMocks());
const policy = {
revision: 2,
configured: true,
minimum_proposals: 3,
minimum_evaluators: 2,
urgent_minimum_proposals: 1,
weights: { price: 40, quality: 20, delivery: 15, history: 15, payment: 10 },
};
const proof = {
id: 9,
version: 1,
created_at: '2026-11-28T10:00:00Z',
reason: 'SYNTHETIC-STOCK-PROOF',
data: { requisition_item_id: 8 },
snapshot: {
item: { description: 'Synthetic material' },
stock_policy: {
minimum_stock_milli: 20000,
usage_context: 'Daily synthetic production',
warehouse: { name: 'Synthetic warehouse' },
},
availability: { free_milli: null },
author: { name: 'Synthetic procurement' },
},
};
function render(
actor = 7,
canRecord = true,
evidence = false,
configured = true,
) {
return renderToStaticMarkup(
<App
initialComponent={UrgentStock}
initialPage={{
component: 'requisitions/urgent-stock',
url: '/requisicoes/3/urgencia-stock',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: {
user: {
id: actor,
tenant_id: 4,
name: 'Synthetic actor',
},
},
workContext: { active: 'procurement.internal' },
organizationAccess: { permissions: ['procurement'] },
requisition: {
id: 3,
number: 'REQ-QA',
priority: 'urgent',
justification: 'Synthetic risk of stopping production.',
},
cycle: 1,
canRecord,
items: [
{
id: 8,
description: 'Synthetic material',
catalogue_snapshot: { stock_item_id: 1 },
},
],
comparisonPolicy: configured
? policy
: { ...policy, urgent_minimum_proposals: undefined },
policies: {
data: [
{
id: 11,
version: 2,
stock_item_id: 1,
item: {
name: 'Synthetic material',
unit: 'un',
},
warehouse: { name: 'Synthetic warehouse' },
minimum_stock_milli: 20000,
usage_context: 'Daily synthetic production',
},
],
prev_page_url: null,
next_page_url: null,
},
evidence: evidence ? [proof] : [],
eligible: evidence ? [proof] : [],
},
}}
/>,
);
}
test('urgent stock preparation is scoped to actor process cycle and immutable evidence version without automatic submission', () => {
const identity =
'procurement-preparations:4:7:procurement.internal:procurement:urgent-stock:3:1:2:8:0';
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:form:data`
? {
item_id: 8,
policy_id: '11',
version: 0,
reason: 'RESTORED-URGENT-STOCK-DRAFT',
operation_key: '117ed627-098c-49a8-a324-d75c4c989473',
}
: undefined,
);
const post = vi.spyOn(router, 'post');
expect(render()).toContain('RESTORED-URGENT-STOCK-DRAFT');
expect(render()).toContain('data-preparation-dirty="true"');
expect(render(8)).not.toContain('RESTORED-URGENT-STOCK-DRAFT');
expect(render(7, true, true)).not.toContain('RESTORED-URGENT-STOCK-DRAFT');
expect(post).not.toHaveBeenCalled();
});
test('approval readers see the evidence without being granted the preparation command', () => {
const html = render(7, false, true);
expect(html).toContain('SYNTHETIC-STOCK-PROOF');
expect(html).toContain('Indeterminado');
expect(html).not.toContain('>Conferir stock mínimo</button>');
expect(render(7, true, false, false)).not.toContain(
'>Conferir stock mínimo</button>',
);
});
test('comparison distinguishes the ordinary count from an applied urgent count and preserves independent evaluations', () => {
const html = renderToStaticMarkup(
<ComparisonPolicySummary
policy={{
...policy,
minimum_proposals: 1,
normal_minimum_proposals: 3,
}}
/>,
);
expect(html).toContain('mínimo de 1 propostas');
expect(html).toContain('mínimo normal é 3');
expect(html).toContain('2 avaliações');
});
test('frozen stock basis summary has no empty section and never represents unknown free stock as zero', () => {
expect(renderToStaticMarkup(<Summary />)).toBe('');
const html = renderToStaticMarkup(<Summary records={[proof]} />);
expect(html).toContain('SYNTHETIC-STOCK-PROOF');
expect(html).toContain('Indeterminado');
expect(html).toContain('Daily synthetic production');
});