Files
atlas-seller-kit/apps/worker/test/platform-catalog-mappers.test.mjs
T

54 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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, '品牌(更新)');
});