114 lines
3.1 KiB
JavaScript
114 lines
3.1 KiB
JavaScript
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const {
|
|
mergeCandidateRowsWithSourceCodes,
|
|
resolveSheet2LocationMatch
|
|
} = require('../sheet2PublicSupplementUtils')
|
|
|
|
const buildLocationByName = (names) =>
|
|
new Map(
|
|
names.map((name, index) => [
|
|
String(name).trim().toUpperCase(),
|
|
{
|
|
id: index + 1,
|
|
name
|
|
}
|
|
])
|
|
)
|
|
|
|
test('mergeCandidateRowsWithSourceCodes 应补回候选集中漏掉的显式编码且不重复已有记录', () => {
|
|
const candidateRows = [
|
|
{
|
|
来源工作表: 'Sheet2',
|
|
资产编码: 'JS-DZ-0172',
|
|
资产名称: '打印机'
|
|
}
|
|
]
|
|
|
|
const sourceRows = [
|
|
{
|
|
来源工作表: 'Sheet2',
|
|
资产编码: 'JS-DZ-0168',
|
|
资产名称: '打印机-喷墨'
|
|
},
|
|
{
|
|
来源工作表: 'Sheet2',
|
|
资产编码: 'JS-DZ-0172',
|
|
资产名称: '打印机'
|
|
}
|
|
]
|
|
|
|
const result = mergeCandidateRowsWithSourceCodes(candidateRows, sourceRows, [
|
|
'JS-DZ-0168',
|
|
'JS-DZ-0172',
|
|
'JS-DZ-9999'
|
|
])
|
|
|
|
assert.deepEqual(
|
|
result.rows.map((row) => row.资产编码),
|
|
['JS-DZ-0172', 'JS-DZ-0168']
|
|
)
|
|
assert.deepEqual(result.missingCodes, ['JS-DZ-9999'])
|
|
assert.deepEqual(result.duplicateSourceCodes, [])
|
|
})
|
|
|
|
test('mergeCandidateRowsWithSourceCodes 遇到源表同编码多行冲突时不应自动选第一条', () => {
|
|
const result = mergeCandidateRowsWithSourceCodes(
|
|
[],
|
|
[
|
|
{
|
|
来源工作表: 'Sheet2',
|
|
资产编码: 'JS-DQ-0373',
|
|
资产名称: '冰箱',
|
|
地址: '佛山顺德仓'
|
|
},
|
|
{
|
|
来源工作表: 'Sheet2',
|
|
资产编码: 'JS-DQ-0373',
|
|
资产名称: '空调',
|
|
地址: '天安'
|
|
}
|
|
],
|
|
['JS-DQ-0373']
|
|
)
|
|
|
|
assert.deepEqual(result.rows, [])
|
|
assert.deepEqual(result.missingCodes, [])
|
|
assert.deepEqual(result.duplicateSourceCodes.map((item) => item.code), ['JS-DQ-0373'])
|
|
assert.equal(result.duplicateSourceCodes[0].rows.length, 2)
|
|
})
|
|
|
|
test('resolveSheet2LocationMatch 应识别带仓储前缀的苏北仓地址', () => {
|
|
const result = resolveSheet2LocationMatch(
|
|
'仓储一部 苏北仓',
|
|
buildLocationByName(['苏北仓库', '常州-仓库'])
|
|
)
|
|
|
|
assert.equal(result.normalizedValue, '苏北仓库')
|
|
assert.equal(result.match?.name, '苏北仓库')
|
|
assert.equal(result.rule, 'sheet2-prefix-override')
|
|
})
|
|
|
|
test('resolveSheet2LocationMatch 应识别带仓储前缀的崔桥工厂仓地址', () => {
|
|
const result = resolveSheet2LocationMatch(
|
|
'仓储二部 崔桥工厂仓',
|
|
buildLocationByName(['常州-仓库'])
|
|
)
|
|
|
|
assert.equal(result.normalizedValue, '常州-仓库')
|
|
assert.equal(result.match?.name, '常州-仓库')
|
|
assert.equal(result.rule, 'sheet2-prefix-alias')
|
|
})
|
|
|
|
test('resolveSheet2LocationMatch 对未明确确认的地址不应猜测映射', () => {
|
|
const result = resolveSheet2LocationMatch(
|
|
'仓储二部 山东仓',
|
|
buildLocationByName(['济南', '常州-仓库'])
|
|
)
|
|
|
|
assert.equal(result.match, null)
|
|
assert.equal(result.normalizedValue, '山东仓')
|
|
assert.equal(result.rule, 'sheet2-prefix-stripped')
|
|
})
|