Files
order-notification-automation/tests/assistant/history-client.test.cjs
T

74 lines
2.3 KiB
JavaScript

'use strict';
const test = require('node:test'),
assert = require('node:assert/strict');
const {
BpmHistoryClient,
normalizeHistory,
HISTORY_ROUTES,
} = require('../../src/modules/bpm/history-client.cjs');
const raw = (version = '1.4', id = '21') => ({
processName: '备损订单更改评审',
processInstanceId: id,
processVersion: version,
startTime: '2026-10-20T10:00:00',
serialNum: 'TEST',
subject: '订单号:123',
businessKey:
'https://bpm.skyworthdigital.com/sso/ssologin.aspx?ReturnUrl=' +
encodeURIComponent('https://bpm.skyworthdigital.com/YZSoft/Forms/Read.aspx?tid=' + id) +
'&todo_token=FIXTURE&todo_account=test',
});
test('history client queries only observed readonly sources and keeps latest version alternatives', async () => {
const calls = [];
let disposed = false;
const client = new BpmHistoryClient({
requestFactory: async () => ({
get: async (route, options) => {
calls.push({ route, options });
return {
status: () => 200,
body: async () =>
Buffer.from(
route === '/'
? "Yiez.clientId='fixture';"
: JSON.stringify({
total: 4,
children: [
raw(),
raw('1.3', '22'),
raw('1.4', '23'),
{ ...raw('1.5', '24'), processName: '其他流程' },
],
}),
),
};
},
dispose: async () => {
disposed = true;
},
}),
});
const rows = await client.scan({}, ['备损订单更改评审']);
assert.equal(rows.length, 2);
assert.equal(rows[0].source, 'history');
assert.equal(rows[0].configurationOnly, true);
assert.equal(rows[0].timestampType, 'process-start');
assert.match(rows[0].nodeName, /未提供/);
assert.equal(rows[0].receivedAt, '2026-10-20T02:00:00.000Z');
assert.deepEqual(
calls.map((c) => c.route),
['/', HISTORY_ROUTES[0]],
);
assert.equal(calls[1].options.params.year, -1);
assert.equal(calls[1].options.params.limit, 100);
assert.equal(disposed, true);
assert.throws(
() => normalizeHistory({ ...raw(), processInstanceId: '22' }),
(e) => e.status === 403,
);
assert.throws(
() => normalizeHistory({ ...raw(), processVersion: '' }),
(e) => e.status === 502,
);
});