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
@@ -0,0 +1,303 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import Responses from '@/components/supplier-responses';
import Improvements from '@/components/supplier-improvements';
import Supplier from '@/pages/suppliers/show';
afterEach(() => vi.restoreAllMocks());
const base = 'procurement-preparations:4:7:procurement.internal:procurement';
const response = {
id: 11,
version: 2,
status: 'draft',
payload: {
title: 'Original response',
received_on: '2026-11-28',
source_reference: 'REF-QA',
statement: 'Original statement',
},
decision: null,
created_by: 9,
reviewed_by: null,
reviewed_at: null,
review_reason: null,
canEdit: true,
canReview: false,
};
const measure = {
id: 12,
version: 2,
status: 'open',
title: 'Original measure',
description: 'Original plan',
responsible_id: 9,
due_on: '2026-12-31',
result: null,
evidence: null,
reviewed_by: null,
review_reason: null,
reviewed_at: null,
canPlan: true,
canExecute: true,
canReview: true,
};
const supplier = {
id: 13,
version: 2,
name: 'Synthetic supplier',
nuit: '123456789',
contact: 'Synthetic',
email: 'qa@example.test',
phone: '123',
address: 'Synthetic location',
category: 'Other',
beneficiaries: 'Synthetic',
document_references: 'REF-QA',
diligence_notes: 'Synthetic',
blocked: false,
next_review: '2027-01-01',
status: 'active',
review_comment: null,
};
function render(
kind: 'responses' | 'improvements' | 'supplier',
overrides = {},
actor = 7,
tenant = 4,
context = 'procurement.internal',
) {
const data =
kind === 'responses'
? {
ready: true,
canCreate: true,
records: [response],
history: null,
}
: {
ready: true,
canCreate: true,
records: [measure],
assignees: [
{ id: 7, name: 'Current' },
{ id: 9, name: 'Other' },
],
today: '2026-11-28',
history: null,
};
return renderToStaticMarkup(
<App
initialComponent={
kind === 'responses'
? Responses
: kind === 'improvements'
? Improvements
: Supplier
}
initialPage={{
component: 'test',
url: '/test',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: { user: { id: actor, tenant_id: tenant } },
workContext: { active: context },
organizationAccess: { permissions: ['procurement'] },
data,
evaluationId: 3,
names: { 7: 'Current', 9: 'Other' },
reportOnly: false,
generatedAt: '2026-11-28T00:00:00Z',
supplier,
documents: [],
canEdit: true,
canDocuments: true,
canReview: true,
...overrides,
},
}}
/>,
);
}
test.each([
[
'responses',
':create',
{
payload: {
title: 'PRIVATE-SUPPLIER-PREPARATION',
received_on: '2026-11-28',
source_reference: 'REF-QA',
statement: 'Prepared statement',
},
},
],
[
'responses',
':record:11:2:draft:true:false:edit',
{
version: 2,
payload: {
...response.payload,
statement: 'PRIVATE-SUPPLIER-PREPARATION',
},
},
],
[
'improvements',
':create',
{
title: 'PRIVATE-SUPPLIER-PREPARATION',
description: 'Prepared plan',
responsible_id: '7',
due_on: '2026-12-31',
},
],
[
'improvements',
':record:12:2:open:true:true:true:plan',
{
version: 2,
title: 'PRIVATE-SUPPLIER-PREPARATION',
description: 'Prepared plan',
responsible_id: '7',
due_on: '2026-12-31',
reason: 'Synthetic reason',
},
],
[
'improvements',
':record:12:2:open:true:true:true:progress',
{
version: 2,
result: 'PRIVATE-SUPPLIER-PREPARATION',
evidence: 'Synthetic evidence',
},
],
[
'improvements',
':record:12:2:open:true:true:true:decision',
{ version: 2, reason: 'PRIVATE-SUPPLIER-PREPARATION' },
],
] as const)(
'%s %s preparation stays in its actor/company/context/evaluation and outside report mode',
(kind, suffix, prepared) => {
const identity = `${base}:supplier-${kind}:3:true:true:false`;
const restore = vi
.spyOn(router, 'restore')
.mockImplementation((k) =>
k === `${identity}${suffix}:data`
? prepared
: k === `${identity}:operation`
? '11111111-1111-4111-8111-111111111111'
: undefined,
);
const post = vi.spyOn(router, 'post');
expect(render(kind)).toContain('PRIVATE-SUPPLIER-PREPARATION');
expect(render(kind)).toContain('data-preparation-dirty="true"');
expect(render(kind, {}, 8)).not.toContain(
'PRIVATE-SUPPLIER-PREPARATION',
);
expect(render(kind, {}, 7, 5)).not.toContain(
'PRIVATE-SUPPLIER-PREPARATION',
);
expect(render(kind, {}, 7, 4, 'finance')).not.toContain(
'PRIVATE-SUPPLIER-PREPARATION',
);
expect(render(kind, { evaluationId: 4 })).not.toContain(
'PRIVATE-SUPPLIER-PREPARATION',
);
expect(render(kind, { reportOnly: true })).not.toContain(
'PRIVATE-SUPPLIER-PREPARATION',
);
if (suffix.startsWith(':record')) {
const data =
kind === 'responses'
? {
ready: true,
canCreate: true,
records: [{ ...response, version: 3 }],
history: null,
}
: {
ready: true,
canCreate: true,
records: [{ ...measure, version: 3 }],
assignees: [],
today: '2026-11-28',
history: null,
};
expect(render(kind, { data })).not.toContain(
'PRIVATE-SUPPLIER-PREPARATION',
);
}
expect(restore).toHaveBeenCalledWith(`${identity}:operation`);
expect(post).not.toHaveBeenCalled();
},
);
test('independent response analysis is source/version scoped without replacing the original record', () => {
const reviewing = {
...response,
status: 'review',
canEdit: false,
canReview: true,
};
const data = {
ready: true,
canCreate: true,
records: [reviewing],
history: null,
};
vi.spyOn(router, 'restore').mockImplementation((k) =>
k ===
`${base}:supplier-responses:3:true:true:false:record:11:2:review:false:true:review:data`
? {
version: 2,
outcome: 'accepted',
reason: 'RESPONSE-REVIEW-QA',
follow_up: 'Synthetic follow-up',
response_reference: 'REF-QA',
}
: undefined,
);
expect(render('responses', { data })).toContain('RESPONSE-REVIEW-QA');
expect(render('responses', { data })).toContain('Original statement');
expect(
render('responses', {
data: { ...data, records: [{ ...reviewing, version: 3 }] },
}),
).not.toContain('RESPONSE-REVIEW-QA');
expect(
render('responses', {
data: { ...data, records: [{ ...reviewing, canReview: false }] },
}),
).not.toContain('RESPONSE-REVIEW-QA');
});
test('supplier validation preparation follows its exact native version without remembering uploads', () => {
vi.spyOn(router, 'restore').mockImplementation((k) =>
k === `${base}:supplier-review:13:2:data`
? { status: 'active', comment: 'SUPPLIER-REVIEW-QA' }
: undefined,
);
const post = vi.spyOn(router, 'post');
expect(render('supplier')).toContain('SUPPLIER-REVIEW-QA');
expect(
render('supplier', { supplier: { ...supplier, version: 3 } }),
).not.toContain('SUPPLIER-REVIEW-QA');
expect(render('supplier', { canReview: false })).not.toContain(
'SUPPLIER-REVIEW-QA',
);
expect(render('supplier', {}, 8)).not.toContain('SUPPLIER-REVIEW-QA');
expect(post).not.toHaveBeenCalled();
});
test('unchanged native supplier forms remain clean', () => {
vi.spyOn(router, 'restore').mockReturnValue(undefined);
expect(render('responses')).not.toContain('data-preparation-dirty="true"');
expect(render('improvements')).not.toContain(
'data-preparation-dirty="true"',
);
expect(render('supplier')).not.toContain('data-preparation-dirty="true"');
});