141 lines
3.5 KiB
JavaScript
141 lines
3.5 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const OperationLogService = require('../../../../app/service/systems/operation_log');
|
|
|
|
function createServiceHarness(options = {}) {
|
|
const calls = {};
|
|
const rows = options.rows || [{
|
|
id: 1,
|
|
operation_code: 'ORDER_CREATE',
|
|
operator_name: 'Alice',
|
|
created_at: '2026-04-19 10:00:00',
|
|
external_log_type: 'NONE',
|
|
external_log_id: null,
|
|
platform_code: 'web',
|
|
message: 'created',
|
|
}];
|
|
|
|
const app = {
|
|
getOperationCodeName(code) {
|
|
return `name:${code}`;
|
|
},
|
|
getPlatformName(code) {
|
|
return `platform:${code}`;
|
|
},
|
|
formatDate(value) {
|
|
return `formatted:${value}`;
|
|
},
|
|
};
|
|
|
|
const model = {
|
|
OperationLog: {
|
|
async findAndCountAll(args = {}) {
|
|
calls.findAndCountAllArgs = args;
|
|
return {
|
|
rows,
|
|
count: options.count == null ? rows.length : options.count,
|
|
};
|
|
},
|
|
},
|
|
};
|
|
|
|
const ctx = {
|
|
app,
|
|
model,
|
|
user: {
|
|
store_id: 100000,
|
|
},
|
|
logger: {
|
|
info() {},
|
|
error() {},
|
|
},
|
|
};
|
|
|
|
return {
|
|
service: new OperationLogService(ctx),
|
|
calls,
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systems/operation_log.queryOrderLogs.test.js', () => {
|
|
it('should query order logs with business_type order and map pagination', async () => {
|
|
const { service, calls } = createServiceHarness({
|
|
count: 21,
|
|
rows: [{
|
|
id: 2,
|
|
operation_code: 'ORDER_CANCEL',
|
|
operator_name: 'Bob',
|
|
created_at: '2026-04-19 12:00:00',
|
|
external_log_type: 'ORDER',
|
|
external_log_id: 9,
|
|
platform_code: 'pda',
|
|
message: 'cancelled',
|
|
}],
|
|
});
|
|
|
|
const result = await service.queryOrderLogs({
|
|
id: 88,
|
|
warehouseId: 100000,
|
|
page: 2,
|
|
pageSize: 10,
|
|
});
|
|
|
|
assert.deepEqual(calls.findAndCountAllArgs.where, {
|
|
business_type: 'order',
|
|
business_id: 88,
|
|
warehouse_id: 100000,
|
|
});
|
|
assert.equal(calls.findAndCountAllArgs.offset, 10);
|
|
assert.equal(calls.findAndCountAllArgs.limit, 10);
|
|
assert.deepEqual(calls.findAndCountAllArgs.attributes, [
|
|
'id',
|
|
'operation_code',
|
|
'operator_name',
|
|
'created_at',
|
|
'external_log_type',
|
|
'external_log_id',
|
|
'platform_code',
|
|
'message',
|
|
]);
|
|
assert.equal(result.pagination.page, 2);
|
|
assert.equal(result.pagination.pageSize, 10);
|
|
assert.equal(result.pagination.total, 21);
|
|
assert.equal(result.pagination.totalPages, 3);
|
|
assert.equal(result.list[0].operation_name, 'name:ORDER_CANCEL');
|
|
assert.equal(result.list[0].platform_name, 'platform:pda');
|
|
assert.equal(result.list[0].created_at, 'formatted:2026-04-19 12:00:00');
|
|
});
|
|
|
|
it('should query receiving logs with business_type receiving', async () => {
|
|
const { service, calls } = createServiceHarness({
|
|
count: 5,
|
|
rows: [{
|
|
id: 3,
|
|
operation_code: 'RECEIVING_REVIEW',
|
|
operator_name: 'Alice',
|
|
created_at: '2026-04-19 13:00:00',
|
|
external_log_type: 'NONE',
|
|
external_log_id: null,
|
|
platform_code: 'web',
|
|
message: 'reviewed',
|
|
}],
|
|
});
|
|
|
|
const result = await service.queryReceivingLogs({
|
|
id: 501,
|
|
warehouseId: 100000,
|
|
page: 1,
|
|
pageSize: 20,
|
|
});
|
|
|
|
assert.deepEqual(calls.findAndCountAllArgs.where, {
|
|
business_type: 'receiving',
|
|
business_id: 501,
|
|
warehouse_id: 100000,
|
|
});
|
|
assert.equal(result.pagination.total, 5);
|
|
assert.equal(result.list[0].operation_name, 'name:RECEIVING_REVIEW');
|
|
});
|
|
});
|