97 lines
2.3 KiB
JavaScript
97 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const LocationZoneService = require('../../../../app/service/systems/location_zone');
|
|
|
|
function createHarness({ storeId = 1, spaces = [] } = {}) {
|
|
const rows = spaces.map(item => ({
|
|
...item,
|
|
deleted_at: item.deleted_at || null,
|
|
}));
|
|
|
|
const ctx = {
|
|
app: {
|
|
config: {},
|
|
},
|
|
user: {
|
|
store_id: storeId,
|
|
},
|
|
logger: {
|
|
error() {},
|
|
},
|
|
model: {
|
|
LocationSpace: {
|
|
async findOne({ where = {}, attributes } = {}) {
|
|
const matched = rows.find(row => {
|
|
if (Number(row.id) !== Number(where.id)) {
|
|
return false;
|
|
}
|
|
|
|
if (Object.prototype.hasOwnProperty.call(where, 'deleted_at') && where.deleted_at === null && row.deleted_at !== null) {
|
|
return false;
|
|
}
|
|
|
|
if (Object.prototype.hasOwnProperty.call(where, 'warehouse_id') && Number(row.warehouse_id) !== Number(where.warehouse_id)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
if (!matched) {
|
|
return null;
|
|
}
|
|
|
|
if (!Array.isArray(attributes) || attributes.length === 0) {
|
|
return { ...matched };
|
|
}
|
|
|
|
return attributes.reduce((acc, key) => {
|
|
acc[key] = matched[key];
|
|
return acc;
|
|
}, {});
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
return {
|
|
service: new LocationZoneService(ctx),
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systems/location_zone.getSpaceInfo.test.js', () => {
|
|
it('存在但不属于当前仓库时应返回仓位不属于当前仓库', async () => {
|
|
const { service } = createHarness({
|
|
storeId: 1,
|
|
spaces: [
|
|
{
|
|
id: 1001,
|
|
warehouse_id: 2,
|
|
location_type_id: 1,
|
|
space_code: 'A01-01-01',
|
|
custom_name: null,
|
|
custom_barcode: null,
|
|
space_status: 1,
|
|
pick_sequence: 1,
|
|
},
|
|
],
|
|
});
|
|
|
|
await assert.rejects(async () => {
|
|
await service.getSpaceInfo(1001);
|
|
}, /仓位不属于当前仓库/);
|
|
});
|
|
|
|
it('全局不存在时应返回仓位不存在', async () => {
|
|
const { service } = createHarness({
|
|
storeId: 1,
|
|
spaces: [],
|
|
});
|
|
|
|
await assert.rejects(async () => {
|
|
await service.getSpaceInfo(99999);
|
|
}, /仓位不存在/);
|
|
});
|
|
});
|