86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const StockTransactionService = require('../../../../app/service/systems/stock_transaction');
|
|
|
|
function createServiceHarness() {
|
|
const calls = {
|
|
createArgs: null,
|
|
};
|
|
|
|
const model = {
|
|
StockTransaction: {
|
|
async create(payload, options) {
|
|
calls.createArgs = {
|
|
payload,
|
|
options,
|
|
};
|
|
return {
|
|
id: 1,
|
|
...payload,
|
|
};
|
|
},
|
|
},
|
|
};
|
|
|
|
const ctx = {
|
|
model,
|
|
app: {
|
|
model,
|
|
},
|
|
};
|
|
|
|
const service = new StockTransactionService(ctx);
|
|
|
|
return {
|
|
service,
|
|
calls,
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systems/stock_transaction.create.test.js', () => {
|
|
it('should create stock transaction with snapshot fields', async () => {
|
|
const { service, calls } = createServiceHarness();
|
|
const transaction = {
|
|
id: 'tx-1',
|
|
};
|
|
|
|
const result = await service.create({
|
|
transaction_type: 'INBOUND',
|
|
warehouse_id: 100000,
|
|
store_id: 1000000,
|
|
stock_id: 200001,
|
|
storage_id: 300001,
|
|
space_id: 400001,
|
|
quantity: 12,
|
|
batch_no: 'BATCH-001',
|
|
inventory_type: 'ZP',
|
|
order_type: 'SCRK',
|
|
order_no: 'EO-001',
|
|
order_id: 500001,
|
|
receiving_id: 600001,
|
|
entry_order_id: 700001,
|
|
operator_id: 'op-1',
|
|
operator_name: '测试人员',
|
|
remark: '测试流水',
|
|
before_quantity: 88,
|
|
after_quantity: 100,
|
|
before_locked_quantity: 5,
|
|
after_locked_quantity: 5,
|
|
created_at: new Date('2026-04-09T08:00:00Z'),
|
|
}, {
|
|
transaction,
|
|
});
|
|
|
|
assert.equal(result.id, 1);
|
|
assert.ok(calls.createArgs, '应调用 StockTransaction.create');
|
|
assert.equal(calls.createArgs.options.transaction, transaction);
|
|
assert.equal(calls.createArgs.payload.before_quantity, 88);
|
|
assert.equal(calls.createArgs.payload.after_quantity, 100);
|
|
assert.equal(calls.createArgs.payload.before_locked_quantity, 5);
|
|
assert.equal(calls.createArgs.payload.after_locked_quantity, 5);
|
|
assert.equal(calls.createArgs.payload.quantity, 12);
|
|
assert.equal(calls.createArgs.payload.transaction_type, 'INBOUND');
|
|
});
|
|
});
|