WMS_MAIN/test/app/service/systems/storage.receiving.getDetail.test.js
liufumingren d711ba9c21 0506更新
Co-authored-by: Copilot <copilot@github.com>
2026-05-06 17:53:54 +08:00

120 lines
2.9 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const ReceivingService = require('../../../../app/service/systems/storage/receiving');
describe('test/app/service/systems/storage.receiving.getDetail.test.js', () => {
it('should include box_remainder and box_weight in receiving detail items', async () => {
const receivingRow = {
id: 123,
warehouse_id: 100000,
receiving_number: 'RCV202605060001',
dataValues: {},
};
const detailRows = [
{
id: 501,
receiving_id: 123,
product_name: '测试商品A',
box_remainder: 2,
box_weight: 18.5,
toJSON() {
return {
id: this.id,
receiving_id: this.receiving_id,
product_name: this.product_name,
box_remainder: this.box_remainder,
box_weight: this.box_weight,
};
},
},
{
id: 502,
receiving_id: 123,
product_name: '测试商品B',
box_remainder: null,
box_weight: null,
toJSON() {
return {
id: this.id,
receiving_id: this.receiving_id,
product_name: this.product_name,
box_remainder: this.box_remainder,
box_weight: this.box_weight,
};
},
},
];
const model = {
Receiving: {
async findOne() {
return receivingRow;
},
},
ReceivingDetail: {
async findAll() {
return detailRows;
},
async count() {
return detailRows.length;
},
},
FileReference: {
async findAll({ where }) {
if (where.business_type === 'receivingItem') {
return [
{
business_id: 501,
file_id: 9001,
file: {
file_url: 'https://example.com/item-501.png',
},
},
];
}
return [];
},
},
File: {},
};
const ctx = {
user: {
store_id: 100000,
},
app: {
Sequelize: {
Op: {
in: 'in',
},
},
model,
},
model,
};
const service = new ReceivingService(ctx);
const result = await service.getReceivingDetail({
id: 123,
pagination: {
page: 1,
pageSize: 10,
},
});
assert.equal(result.code, 200);
const receivingPayload = result.data.receiving;
const details = Array.isArray(receivingPayload.details)
? receivingPayload.details
: receivingPayload.dataValues.details;
assert.ok(Array.isArray(details));
assert.equal(Number(details[0].box_remainder), 2);
assert.equal(Number(details[0].box_weight), 18.5);
assert.equal(Number(details[1].box_remainder), 0);
assert.equal(Number(details[1].box_weight), 0);
});
});