WMS_MAIN/test/app/service/systems/storage.receiving.bindDetailProduct.test.js
liufumingren 5ce689d771 1
Co-authored-by: Copilot <copilot@github.com>
2026-04-30 19:20:31 +08:00

103 lines
2.2 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const ReceivingService = require('../../../../app/service/systems/storage/receiving');
function createHarness(overrides = {}) {
const calls = {
stockWarehouseFindOne: 0,
};
const receivingDetail = {
id: 1001,
receiving_id: 5001,
receiving: {
id: 5001,
warehouse_id: 100000,
store_id: 1000000,
store_name: '测试货主',
status: 'completed',
is_review: 1,
...(overrides.receiving || {}),
},
};
const ctx = {
user: {
store_id: 100000,
employees_id: 9001,
employees_name: '测试员',
id: 9001,
},
logger: {
error() {},
warn() {},
info() {},
},
service: {
systems: {
operationLog: {
async createOperationLog() {},
},
},
},
};
const app = {
model: {
ReceivingDetail: {
async findOne() {
return receivingDetail;
},
},
StockWarehouse: {
async findOne() {
calls.stockWarehouseFindOne += 1;
return null;
},
},
},
};
ctx.app = app;
const service = new ReceivingService(ctx);
return {
service,
calls,
};
}
describe('test/app/service/systems/storage.receiving.bindDetailProduct.test.js', () => {
it('should reject binding when receiving is already reviewed', async () => {
const { service, calls } = createHarness();
const result = await service.bindDetailProduct({
detail_id: 1001,
system_product_id: 2001,
});
assert.equal(result.code, 400);
assert.match(String(result.message || ''), /已审核/);
assert.equal(calls.stockWarehouseFindOne, 0);
});
it('should reject binding when receiving is cancelled', async () => {
const { service, calls } = createHarness({
receiving: {
is_review: 0,
status: 'cancelled',
},
});
const result = await service.bindDetailProduct({
detail_id: 1001,
system_product_id: 2001,
});
assert.equal(result.code, 400);
assert.match(String(result.message || ''), /已作废/);
assert.equal(calls.stockWarehouseFindOne, 0);
});
});