102 lines
2.4 KiB
JavaScript
102 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
|
|
/**
|
|
* 构造 print_stations 模型测试所需的最小 Sequelize 类型集合。
|
|
* @return {Object} Sequelize 类型集合。
|
|
*/
|
|
function createSequelizeTypes() {
|
|
const makeType = sql => ({
|
|
toSql() {
|
|
return sql;
|
|
},
|
|
});
|
|
|
|
const integerType = makeType('INTEGER');
|
|
integerType.UNSIGNED = makeType('INTEGER UNSIGNED');
|
|
|
|
return {
|
|
INTEGER: integerType,
|
|
BIGINT: {
|
|
UNSIGNED: makeType('BIGINT UNSIGNED'),
|
|
},
|
|
STRING: length => makeType(`VARCHAR(${length})`),
|
|
DATE: makeType('DATETIME'),
|
|
TINYINT: makeType('TINYINT'),
|
|
JSON: makeType('JSON'),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 构造加载 print_stations 模型所需的最小应用对象。
|
|
* @return {Object} 应用对象。
|
|
*/
|
|
function createApp() {
|
|
return {
|
|
Sequelize: createSequelizeTypes(),
|
|
model: {
|
|
define(name, attributes, options) {
|
|
return {
|
|
name,
|
|
rawAttributes: attributes,
|
|
options,
|
|
};
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
describe('test/app/model/print_stations.test.js', () => {
|
|
it('should return empty express_bind_printer by default', () => {
|
|
const PrintStations = require('../../../app/model/print_stations')(createApp());
|
|
|
|
const normalized = PrintStations.normalizeSubjectConfig(null);
|
|
|
|
assert.deepEqual(PrintStations.DEFAULT_SUBJECT_CONFIG, {
|
|
express_bind_printer: [],
|
|
});
|
|
assert.deepEqual(normalized, {
|
|
express_bind_printer: [],
|
|
});
|
|
});
|
|
|
|
it('should normalize express_bind_printer list', () => {
|
|
const PrintStations = require('../../../app/model/print_stations')(createApp());
|
|
|
|
const normalized = PrintStations.normalizeSubjectConfig({
|
|
express_bind_printer: [
|
|
{
|
|
printer_name: ' 打印机A ',
|
|
express_code: ' STO ',
|
|
},
|
|
],
|
|
});
|
|
|
|
assert.deepEqual(normalized.express_bind_printer, [
|
|
{
|
|
printer_name: '打印机A',
|
|
express_code: 'STO',
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should throw with field path when express_bind_printer item is invalid', () => {
|
|
const PrintStations = require('../../../app/model/print_stations')(createApp());
|
|
|
|
assert.throws(
|
|
() => {
|
|
PrintStations.normalizeSubjectConfig({
|
|
express_bind_printer: [
|
|
{
|
|
printer_name: '',
|
|
express_code: 'STO',
|
|
},
|
|
],
|
|
});
|
|
},
|
|
/subject_config\.express_bind_printer\[0\]\.printer_name 不能为空/
|
|
);
|
|
});
|
|
});
|