84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
getAuthToken,
|
|
invokeSystemMethod,
|
|
} = require('../../support/system_method_client');
|
|
|
|
const EXTRA_HEADERS = {
|
|
platform: 'web',
|
|
project: 'all',
|
|
};
|
|
|
|
const FALLBACK_ROLE_IDS = [ 4, 6, 30 ];
|
|
|
|
async function switchToWarehouseRoleWithOrderData(token) {
|
|
let currentToken = token;
|
|
const infoRes = await invokeSystemMethod('user.info', {}, currentToken, EXTRA_HEADERS);
|
|
assert.equal(infoRes.status, 200);
|
|
assert.equal(infoRes.body.flag, 'success');
|
|
assert.equal(infoRes.body.code, 200);
|
|
|
|
const employees = Array.isArray(infoRes.body?.data?.employees) ? infoRes.body.data.employees : [];
|
|
const warehouseRoles = employees.filter(item => item && item.role_type === 'warehouse' && Number(item.id));
|
|
const candidateRoleIds = [ ...new Set([
|
|
...warehouseRoles.map(item => Number(item.id)),
|
|
...FALLBACK_ROLE_IDS,
|
|
].filter(Boolean)) ];
|
|
|
|
assert.ok(candidateRoleIds.length > 0, '当前账号没有可尝试的仓库角色');
|
|
|
|
for (const roleId of candidateRoleIds) {
|
|
const changeRes = await invokeSystemMethod('user.changeRole', {
|
|
roleId,
|
|
}, currentToken, EXTRA_HEADERS);
|
|
|
|
if (changeRes.status !== 200 || changeRes.body?.flag !== 'success' || changeRes.body?.code !== 200) {
|
|
continue;
|
|
}
|
|
|
|
currentToken = changeRes.body?.data?.token || currentToken;
|
|
|
|
const statsRes = await invokeSystemMethod('order.stats', {
|
|
where: {},
|
|
}, currentToken, EXTRA_HEADERS);
|
|
|
|
assert.equal(statsRes.status, 200);
|
|
assert.equal(statsRes.body.flag, 'success');
|
|
assert.equal(statsRes.body.code, 200);
|
|
|
|
const total = Number(statsRes.body?.data?.total || 0);
|
|
if (total > 0) {
|
|
return {
|
|
token: currentToken,
|
|
};
|
|
}
|
|
}
|
|
|
|
throw new Error('未找到有订单数据的仓库角色');
|
|
}
|
|
|
|
describe('test/app/controller/system.order.getreviewOrderlist.test.js', () => {
|
|
it('should call order.getreviewOrderlist with platform=web project=all', async () => {
|
|
const { token } = await getAuthToken();
|
|
const switched = await switchToWarehouseRoleWithOrderData(token);
|
|
|
|
const res = await invokeSystemMethod('order.getreviewOrderlist', {
|
|
pagination: {
|
|
page: 1,
|
|
pageSize: 10,
|
|
},
|
|
where: {},
|
|
}, switched.token, EXTRA_HEADERS);
|
|
|
|
assert.equal(res.status, 200);
|
|
assert.equal(res.body.flag, 'success');
|
|
assert.equal(res.body.code, 200);
|
|
assert.ok(res.body.data);
|
|
assert.ok(Array.isArray(res.body.data.list));
|
|
assert.ok(res.body.data.pagination);
|
|
assert.equal(typeof res.body.data.pagination.total, 'number');
|
|
});
|
|
});
|