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,120 @@
import { App, router } from '@inertiajs/react';
import { renderToStaticMarkup } from 'react-dom/server';
import { afterEach, expect, test, vi } from 'vitest';
import Conflicts from '@/pages/conflicts/index';
import History from '@/pages/conflicts/show';
afterEach(() => vi.restoreAllMocks());
const identity = 'conflicts:4:7:finance:finance';
const declaration = {
id: 3,
user_id: 7,
supplier_id: 1,
requisition_id: null,
has_conflict: true,
known_since: '2026-01-01',
declared_at: '2026-11-28T00:00:00Z',
reason: 'Original synthetic conflict',
previous_id: null,
root_id: null,
author: { name: 'Synthetic actor' },
supplier: { name: 'Synthetic supplier' },
requisition: null,
};
function render(
history = false,
actor = 7,
tenant = 4,
context = 'finance',
canCorrect = true,
sourceId = 3,
) {
return renderToStaticMarkup(
<App
initialComponent={history ? History : Conflicts}
initialPage={{
component: history ? 'conflicts/show' : 'conflicts/index',
url: '/conflitos',
version: null,
clearHistory: false,
encryptHistory: true,
props: {
errors: {},
auth: {
user: {
id: actor,
tenant_id: tenant,
name: 'Synthetic actor',
},
},
workContext: { active: context },
organizationAccess: { permissions: ['finance'] },
history: [{ ...declaration, id: sourceId }],
canCorrect,
declarations: {
data: [],
prev_page_url: null,
next_page_url: null,
},
suppliers: [{ id: 1, name: 'Synthetic supplier' }],
requisitions: [],
},
}}
/>,
);
}
test('personal declaration preparation remains private to its actor company and context without submitting', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:new:data`
? {
scope: 'supplier',
supplier_id: '1',
requisition_id: '',
has_conflict: '1',
known_since: '2026-01-01',
reason: 'PERSONAL-DRAFT-QA',
}
: undefined,
);
const post = vi.spyOn(router, 'post');
expect(render()).toContain('PERSONAL-DRAFT-QA');
expect(render()).toContain('data-preparation-dirty="true"');
expect(render(false, 8)).not.toContain('PERSONAL-DRAFT-QA');
expect(render(false, 7, 5)).not.toContain('PERSONAL-DRAFT-QA');
expect(render(false, 7, 4, 'procurement.internal')).not.toContain(
'PERSONAL-DRAFT-QA',
);
expect(post).not.toHaveBeenCalled();
});
test('correction preparation follows the immutable source version and current correction authority', () => {
vi.spyOn(router, 'restore').mockImplementation((key) =>
key === `${identity}:correction:3:${declaration.declared_at}:true:data`
? {
reason: 'CORRECTION-DRAFT-QA',
known_since: '2026-02-01',
}
: undefined,
);
const put = vi.spyOn(router, 'put');
const html = render(true);
expect(html).toContain('CORRECTION-DRAFT-QA');
expect(html).toContain('Original synthetic conflict');
expect(html).toContain('data-preparation-dirty="true"');
expect(render(true, 8)).not.toContain('CORRECTION-DRAFT-QA');
expect(render(true, 7, 5)).not.toContain('CORRECTION-DRAFT-QA');
expect(render(true, 7, 4, 'finance', false)).not.toContain(
'CORRECTION-DRAFT-QA',
);
expect(render(true, 7, 4, 'finance', true, 4)).not.toContain(
'CORRECTION-DRAFT-QA',
);
expect(put).not.toHaveBeenCalled();
});
test('unchanged declaration and correction do not mark a preparation dirty', () => {
vi.spyOn(router, 'restore').mockReturnValue(undefined);
expect(render()).toContain('data-preparation-dirty="false"');
expect(render(true)).toContain('data-preparation-dirty="false"');
expect(render(true, 7, 4, 'finance', false)).not.toContain(
'data-preparation-dirty',
);
});