128 lines
4.0 KiB
JavaScript
128 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const ReceivingService = require('../../../../app/service/systems/storage/receiving');
|
|
|
|
function createService() {
|
|
const excelCalls = [];
|
|
const ctx = {
|
|
app: {
|
|
config: {},
|
|
Sequelize: {
|
|
Op: {},
|
|
},
|
|
},
|
|
user: {
|
|
store_id: 2001,
|
|
},
|
|
logger: {
|
|
info() {},
|
|
warn() {},
|
|
error() {},
|
|
},
|
|
service: {
|
|
systems: {
|
|
excel: {
|
|
async generateAndUpload(options) {
|
|
excelCalls.push(options);
|
|
return {
|
|
fileKey: options.filename,
|
|
url: `https://cdn.example.com/${options.filename}`,
|
|
};
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const service = new ReceivingService(ctx);
|
|
return {
|
|
service,
|
|
excelCalls,
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systems/storage.receiving.report.test.js', () => {
|
|
it('should build and upload completion excel in a single sheet with one preview column', async () => {
|
|
const { service, excelCalls } = createService();
|
|
|
|
const result = await service.uploadCompletionExcelReport({
|
|
receiving: {
|
|
id: 123,
|
|
receiving_number: 'RCV202604040001',
|
|
store_name: '测试货主',
|
|
warehouse_id: 2001,
|
|
delivery_method: 'truck',
|
|
license_plate: '粤A12345',
|
|
tracking_number: 'YT123456789',
|
|
total_boxes: 3,
|
|
total_pallets: 1,
|
|
remark: '完成收货测试',
|
|
receiving_end_time: new Date('2026-04-04T12:30:00Z'),
|
|
details: [
|
|
{
|
|
id: 501,
|
|
product_name: '测试商品A',
|
|
system_product_id: 9001,
|
|
barcode: 'SKU-001',
|
|
actual_quantity: 8,
|
|
weight: 12,
|
|
},
|
|
],
|
|
},
|
|
operator: {
|
|
employees_name: '测试员',
|
|
},
|
|
stats: {
|
|
total_details: 1,
|
|
matched_details: 1,
|
|
unmatched_details: 0,
|
|
total_quantity: 8,
|
|
},
|
|
detailImageMap: new Map([
|
|
[ '501', [
|
|
{ url: 'https://example.com/image-1.png' },
|
|
{ url: 'https://example.com/image-2.png' },
|
|
]],
|
|
]),
|
|
receivingImages: [
|
|
{ url: 'https://example.com/main-image.png' },
|
|
],
|
|
});
|
|
|
|
assert.equal(excelCalls.length, 1);
|
|
const [ options ] = excelCalls;
|
|
assert.equal(options.filename, '收货完成_RCV202604040001.xlsx');
|
|
assert.ok(String(options.dir || '').includes('receiving/completed'));
|
|
assert.equal(options.expireDays, 90);
|
|
assert.ok(Array.isArray(options.sheets));
|
|
assert.equal(options.sheets.length, 1);
|
|
|
|
const [ sheet ] = options.sheets;
|
|
assert.equal(sheet.name, '收货清单');
|
|
assert.ok(Array.isArray(sheet.rows));
|
|
assert.equal(sheet.skipHeader, true);
|
|
|
|
const receivingNumberRow = sheet.rows.find(item => Array.isArray(item) && item[0] === '收货单号');
|
|
assert.ok(receivingNumberRow, '应在主表区域包含收货单号行');
|
|
|
|
const summaryImageRow = sheet.rows.find(item => Array.isArray(item) && item[0] === '收货图片');
|
|
assert.ok(summaryImageRow, '应在主表区域包含收货图片行');
|
|
assert.match(String(summaryImageRow[1]?.text || summaryImageRow[1] || ''), /main-image/);
|
|
|
|
const detailHeaderRow = sheet.rows.find(item => Array.isArray(item) && item[0] === '序号' && item[1] === '商品名称');
|
|
assert.ok(detailHeaderRow, '明细表头应出现在下方明细区开始处');
|
|
|
|
const detailRow = sheet.rows.find(item => Array.isArray(item) && item[1] === '测试商品A');
|
|
assert.ok(detailRow, '应在单 sheet 中包含明细行');
|
|
assert.match(String(detailRow[11]?.text || detailRow[11] || ''), /image-1\.png/);
|
|
assert.equal(detailRow[10], '');
|
|
|
|
assert.ok(Array.isArray(sheet.styledRows));
|
|
assert.ok(sheet.styledRows.some(item => item && item.style && item.style.font && item.style.font.bold), '应包含表头加粗样式');
|
|
assert.ok(Array.isArray(sheet.embeddedImages));
|
|
assert.equal(sheet.embeddedImages.length, 3);
|
|
assert.equal(result.url, 'https://cdn.example.com/收货完成_RCV202604040001.xlsx');
|
|
});
|
|
});
|