95 lines
2.6 KiB
JavaScript
95 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs/promises';
|
|
import {
|
|
actionsFor,
|
|
commandEnvelope,
|
|
limitMinor,
|
|
limitMajor,
|
|
} from '../integrations/sgf/internal-requisitions/screen.mjs';
|
|
|
|
const own = { requester_id: 1, status: 'draft', steps: [] };
|
|
assert.deepEqual(actionsFor(own, 1, { prepare: true }), ['edit', 'submit']);
|
|
assert.deepEqual(actionsFor(own, 2, { prepare: true }), []);
|
|
const pending = {
|
|
...own,
|
|
status: 'pending',
|
|
steps: [
|
|
{ role: 'department_head', decision: 'pending', approver_id: null },
|
|
],
|
|
};
|
|
assert.deepEqual(actionsFor(pending, 1, { department_head: true }), []);
|
|
assert.deepEqual(actionsFor(pending, 2, { department_head: true }), [
|
|
'approved',
|
|
'rejected',
|
|
]);
|
|
assert.deepEqual(actionsFor(pending, 2, {}), []);
|
|
assert.deepEqual(
|
|
actionsFor(
|
|
{
|
|
...pending,
|
|
steps: [
|
|
{
|
|
role: 'department_head',
|
|
decision: 'approved',
|
|
approver_id: 2,
|
|
},
|
|
{ role: 'finance', decision: 'pending' },
|
|
],
|
|
},
|
|
2,
|
|
{ finance: true },
|
|
),
|
|
[],
|
|
);
|
|
assert.deepEqual(
|
|
actionsFor({ ...pending, status: 'approved' }, 2, {
|
|
department_head: true,
|
|
}),
|
|
[],
|
|
);
|
|
const key = '12345678-1234-4234-8234-123456789012';
|
|
assert.deepEqual(commandEnvelope(key, 3, { decision: 'approved' }), {
|
|
operation_key: key,
|
|
version: 3,
|
|
decision: 'approved',
|
|
});
|
|
assert.equal(limitMinor('1000.01'), 100001);
|
|
assert.equal(limitMajor(100001), '1000.01');
|
|
assert.equal(limitMinor('1000000000000.00'), 100000000000000);
|
|
assert.throws(() => limitMinor('1.001'));
|
|
assert.throws(() => limitMinor('1000000000000.01'));
|
|
const html = await fs.readFile(
|
|
new URL(
|
|
'../integrations/sgf/internal-requisitions/screen.php',
|
|
import.meta.url,
|
|
),
|
|
'utf8',
|
|
);
|
|
for (const text of [
|
|
'Guardar rascunho',
|
|
'Histórico por versão',
|
|
'Centro de custo',
|
|
'Parametrização',
|
|
'Compras internas',
|
|
'ir-contract',
|
|
])
|
|
assert.ok(html.includes(text));
|
|
const script = await fs.readFile(
|
|
new URL(
|
|
'../integrations/sgf/internal-requisitions/screen.mjs',
|
|
import.meta.url,
|
|
),
|
|
'utf8',
|
|
);
|
|
assert.ok(!script.includes('innerHTML'));
|
|
for (const header of ['X-CSRF-TOKEN', 'X-SGF-Context', 'X-Purchasing-Context'])
|
|
assert.ok(script.includes(header));
|
|
console.log(
|
|
JSON.stringify({
|
|
passed: true,
|
|
checks: 23,
|
|
browser_used: false,
|
|
scope: 'screen action model, exact limits, retry envelope, safe text rendering and context headers',
|
|
}),
|
|
);
|