146 lines
3.6 KiB
JavaScript
146 lines
3.6 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const StockStoreService = require('../../../../app/service/systems/stock_store');
|
|
|
|
function createHarness() {
|
|
const stockTransactionCalls = [];
|
|
const ctx = {
|
|
user: {
|
|
store_id: 100000,
|
|
employees_id: 9001,
|
|
employees_name: '测试用户',
|
|
},
|
|
model: {
|
|
Picking: {
|
|
async findAll() {
|
|
return [
|
|
{
|
|
storage_id: 501,
|
|
space_id: 601,
|
|
quantity: 2,
|
|
},
|
|
{
|
|
storage_id: 502,
|
|
space_id: 602,
|
|
quantity: 1,
|
|
},
|
|
];
|
|
},
|
|
},
|
|
StockWarehouse: {
|
|
async update() {
|
|
return [ 1 ];
|
|
},
|
|
async findByPk() {
|
|
return {
|
|
id: 77,
|
|
warehouse_id: 100000,
|
|
quantity: 5,
|
|
locked_quantity: 1,
|
|
update_at: new Date('2026-05-15T08:00:00.000Z'),
|
|
};
|
|
},
|
|
},
|
|
},
|
|
service: {
|
|
systems: {
|
|
stockTransaction: {
|
|
async create(payload) {
|
|
stockTransactionCalls.push(payload);
|
|
return {
|
|
id: stockTransactionCalls.length,
|
|
};
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const app = {
|
|
Sequelize: {
|
|
Op: {
|
|
gte: Symbol('gte'),
|
|
},
|
|
literal(sql) {
|
|
return sql;
|
|
},
|
|
},
|
|
logger: {
|
|
info() {},
|
|
warn() {},
|
|
error() {},
|
|
},
|
|
};
|
|
|
|
ctx.app = app;
|
|
ctx.logger = app.logger;
|
|
|
|
const service = new StockStoreService(ctx);
|
|
service.getItemStorages = async () => {
|
|
return {
|
|
success: true,
|
|
data: {
|
|
storage: {
|
|
exists: true,
|
|
id: 77,
|
|
storeId: 200001,
|
|
quantity: 10,
|
|
lockedQuantity: 6,
|
|
},
|
|
},
|
|
};
|
|
};
|
|
service.getStoreWarehousePolicyConfigByStockId = async () => {
|
|
return {
|
|
allowOversell: false,
|
|
};
|
|
};
|
|
service.clearItemStorageCache = async () => {};
|
|
|
|
return {
|
|
service,
|
|
stockTransactionCalls,
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systems/stock_store.outbound.picking.test.js', () => {
|
|
it('should write outbound transactions by picking rows with order and location fields', async () => {
|
|
const { service, stockTransactionCalls } = createHarness();
|
|
|
|
const result = await service.outbound(1001, 5, {
|
|
id: 'tx-1',
|
|
}, {
|
|
orderId: 2001,
|
|
orderNo: 'DO-2001',
|
|
orderItemId: 3001,
|
|
});
|
|
|
|
assert.equal(result.success, true);
|
|
assert.equal(stockTransactionCalls.length, 3);
|
|
|
|
assert.equal(stockTransactionCalls[0].storage_id, 501);
|
|
assert.equal(stockTransactionCalls[0].space_id, 601);
|
|
assert.equal(stockTransactionCalls[0].quantity, 2);
|
|
assert.equal(stockTransactionCalls[0].order_id, 2001);
|
|
assert.equal(stockTransactionCalls[0].order_no, 'DO-2001');
|
|
|
|
assert.equal(stockTransactionCalls[1].storage_id, 502);
|
|
assert.equal(stockTransactionCalls[1].space_id, 602);
|
|
assert.equal(stockTransactionCalls[1].quantity, 1);
|
|
assert.equal(stockTransactionCalls[1].order_id, 2001);
|
|
assert.equal(stockTransactionCalls[1].order_no, 'DO-2001');
|
|
|
|
assert.equal(stockTransactionCalls[2].storage_id, null);
|
|
assert.equal(stockTransactionCalls[2].space_id, null);
|
|
assert.equal(stockTransactionCalls[2].quantity, 2);
|
|
assert.equal(stockTransactionCalls[2].order_id, 2001);
|
|
assert.equal(stockTransactionCalls[2].order_no, 'DO-2001');
|
|
|
|
stockTransactionCalls.forEach(payload => {
|
|
assert.equal(payload.store_id, 200001);
|
|
assert.equal(payload.remark, '订单出库');
|
|
});
|
|
});
|
|
});
|