feat(category): 类目树、属性、属性字典维护,新增系统管理员管理类目数据

This commit is contained in:
R524809
2026-09-18 18:55:16 +08:00
parent fcddb11da0
commit 388429dbd0
58 changed files with 4347 additions and 640 deletions
@@ -0,0 +1,53 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import {
flattenPlatformCategories,
mapPlatformAttributes,
} from '../src/platform-catalog-mappers.ts';
test('类目树叶子继承 description_category_id 并保留 type_id', () => {
const rows = flattenPlatformCategories([{
description_category_id: 17027922,
category_name: '儿童玩具',
children: [{ type_id: 8229, type_name: '玩具类型' }],
}]);
assert.equal(rows.length, 2);
assert.deepEqual(rows.map((row) => [row.external_category_id, row.external_type_id]), [
['17027922', '0'],
['17027922', '8229'],
]);
assert.equal(rows[1].parent_key, '17027922:0');
assert.equal(rows[1].path, '儿童玩具 › 玩具类型');
assert.equal(rows[1].is_active, true);
});
test('属性定义按 Ozon 属性 ID 和 complex ID 去重并保留约束', () => {
const rows = mapPlatformAttributes([{
id: 85,
attribute_complex_id: 0,
name: '品牌',
type: 'String',
dictionary_id: 321,
is_required: true,
is_collection: true,
max_value_count: 1000,
category_dependent: false,
}, {
id: 85,
attribute_complex_id: 0,
name: '品牌(更新)',
type: 'String',
dictionary_id: 321,
is_required: true,
is_collection: true,
max_value_count: 2,
}]);
assert.equal(rows.length, 1);
assert.equal(rows[0].platform_attribute_id, '85');
assert.equal(rows[0].complex_id, '0');
assert.equal(rows[0].value_type, 'dictionary');
assert.equal(rows[0].max_value_count, 2);
assert.equal(rows[0].name, '品牌(更新)');
});