import { describe, expect, it } from 'vitest'; import { pickCustomerOrderCategoryCode } from '../src/services/customerOrderEnrichService'; const mappingSelf = [ { sku_code: 'SKU78662536922', customer_sku_name: '抄手皮', category_code: 'CAT_ZICAI', }, ]; const dryRule = [{ keyword: '抄手', category_code: 'CAT_GANZA' }]; describe('pickCustomerOrderCategoryCode', () => { it('keeps submitted category over customer mapping', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: 'CAT_GANZA', skuCode: 'SKU78662536922', itemName: '抄手皮', customerSkus: mappingSelf, smartRules: dryRule, smartClassifyEnabled: true, preferCustomerMapping: true, skuMasterCategory: 'CAT_MASTER', }) ).toBe('CAT_GANZA'); }); it('uses customer mapping when submit has no category', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: null, skuCode: 'SKU78662536922', itemName: '抄手皮', customerSkus: mappingSelf, smartRules: dryRule, smartClassifyEnabled: true, preferCustomerMapping: true, }) ).toBe('CAT_ZICAI'); }); it('uses smart rules when submit and mapping are empty', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: null, skuCode: '', itemName: '抄手皮', customerSkus: [], smartRules: dryRule, smartClassifyEnabled: true, preferCustomerMapping: true, }) ).toBe('CAT_GANZA'); }); it('does not use sku master when preferCustomerMapping and category is empty', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: null, skuCode: 'SKU78662536922', itemName: '抄手皮', customerSkus: [], smartRules: [], smartClassifyEnabled: true, preferCustomerMapping: true, skuMasterCategory: 'CAT_MASTER', }) ).toBeNull(); }); it('keeps parse-filled category and does not overlay mapping', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: 'CAT_GANZA', skuCode: 'SKU78662536922', itemName: '抄手皮', customerSkus: mappingSelf, smartRules: [], smartClassifyEnabled: true, preferCustomerMapping: true, filledCategory: 'should_not_apply_when_submitted', }) ).toBe('CAT_GANZA'); }); it('uses sku master before mapping when preferCustomerMapping is false', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: null, skuCode: 'SKU78662536922', itemName: '抄手皮', customerSkus: mappingSelf, smartRules: [], smartClassifyEnabled: true, preferCustomerMapping: false, skuMasterCategory: 'CAT_MASTER', }) ).toBe('CAT_MASTER'); }); it('fills empty parse line from mapping', () => { expect( pickCustomerOrderCategoryCode({ submittedCategory: null, skuCode: '', itemName: '抄手皮', customerSkus: mappingSelf, smartRules: [], smartClassifyEnabled: true, preferCustomerMapping: true, }) ).toBe('CAT_ZICAI'); }); });