80 lines
2.3 KiB
JavaScript
80 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
|
|
function createSequelizeTypes() {
|
|
const makeType = sql => ({
|
|
toSql() {
|
|
return sql;
|
|
},
|
|
});
|
|
|
|
const unsignedBigInt = length => {
|
|
const type = makeType(`BIGINT(${length})`);
|
|
type.UNSIGNED = makeType(`BIGINT(${length}) UNSIGNED`);
|
|
return type;
|
|
};
|
|
|
|
return {
|
|
BIGINT: unsignedBigInt,
|
|
STRING: length => makeType(`VARCHAR(${length})`),
|
|
INTEGER: length => {
|
|
const type = makeType(`INT(${length})`);
|
|
type.UNSIGNED = makeType(`INT(${length}) UNSIGNED`);
|
|
return type;
|
|
},
|
|
DATE: makeType('DATETIME'),
|
|
literal(value) {
|
|
return {
|
|
toSql() {
|
|
return value;
|
|
},
|
|
};
|
|
},
|
|
};
|
|
}
|
|
|
|
function createApp() {
|
|
const Sequelize = createSequelizeTypes();
|
|
|
|
return {
|
|
Sequelize,
|
|
model: {
|
|
define(name, attributes, options) {
|
|
return {
|
|
name,
|
|
rawAttributes: attributes,
|
|
options,
|
|
belongsTo() {},
|
|
};
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
describe('test/app/model/picking.test.js', () => {
|
|
it('should define wms_picking fields and indexes', () => {
|
|
const app = createApp();
|
|
const Picking = require('../../../app/model/picking')(app);
|
|
|
|
assert.equal(Picking.options.tableName, 'wms_picking');
|
|
assert.equal(Picking.options.comment, '订单储位分配表');
|
|
assert.ok(Picking.rawAttributes.order_id);
|
|
assert.ok(Picking.rawAttributes.order_item_id);
|
|
assert.ok(Picking.rawAttributes.storage_id);
|
|
assert.ok(Picking.rawAttributes.quantity);
|
|
assert.ok(Picking.rawAttributes.space_id);
|
|
assert.ok(Picking.rawAttributes.space_name);
|
|
assert.ok(Picking.rawAttributes.status);
|
|
assert.equal(Picking.rawAttributes.status.defaultValue, 'pending');
|
|
assert.equal(Picking.rawAttributes.quantity.defaultValue, 1);
|
|
|
|
const indexNames = (Picking.options.indexes || []).map(index => index.name);
|
|
assert.ok(indexNames.includes('idx_wms_picking_order_id'));
|
|
assert.ok(indexNames.includes('idx_wms_picking_order_item_id'));
|
|
assert.ok(indexNames.includes('idx_wms_picking_storage_id'));
|
|
assert.ok(indexNames.includes('idx_wms_picking_space_id'));
|
|
assert.ok(indexNames.includes('idx_wms_picking_status'));
|
|
assert.ok(indexNames.includes('idx_wms_picking_order_item_space'));
|
|
});
|
|
}); |