feat(admin): family match util
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { sameFamily } from './family-match'
|
||||||
|
|
||||||
|
const node = (familyId: string | null, goodName: string) => ({ familyId, goodName })
|
||||||
|
|
||||||
|
describe('sameFamily', () => {
|
||||||
|
it('同族(familyId 相等且非空)→ true,名称不同也不影响', () => {
|
||||||
|
expect(
|
||||||
|
sameFamily(node('12', '美国(包邮)T恤-DG001-单面印花'), node('12', '墨西哥(不包邮)卫衣-XX-双面印花')),
|
||||||
|
).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('任一方 familyId 为空 → 回退名称 3 段规则', () => {
|
||||||
|
const a = node(null, '美国(包邮)T恤-DG001-单面印花')
|
||||||
|
expect(sameFamily(a, node(null, '美国(包邮)T恤-DG001-单面印花-某仓'))).toBe(true)
|
||||||
|
expect(sameFamily(a, node('12', '美国(包邮)T恤-DG001-单面印花'))).toBe(true)
|
||||||
|
expect(sameFamily(a, node(null, '美国(不包邮)T恤-DG001-单面印花'))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('familyId 不同 → false(即使名称同段)', () => {
|
||||||
|
expect(
|
||||||
|
sameFamily(node('1', '美国(包邮)T恤-DG001-单面印花'), node('2', '美国(包邮)T恤-DG001-单面印花')),
|
||||||
|
).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('双方均无族且名称不可比 → false', () => {
|
||||||
|
expect(sameFamily(node(null, ''), node(null, '随便'))).toBe(false)
|
||||||
|
expect(sameFamily(node(null, null as unknown as string), node(null, '随便'))).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { sameOriginGroup } from './origin-name'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两个原产品节点是否属于同一产品族:
|
||||||
|
* 优先用服务端返回的 familyId 精确匹配;无族归属时回退名称 3 段规则
|
||||||
|
* (老数据/未回填场景兜底)。
|
||||||
|
*/
|
||||||
|
export function sameFamily(
|
||||||
|
a: { familyId?: string | null; goodName?: string | null },
|
||||||
|
b: { familyId?: string | null; goodName?: string | null },
|
||||||
|
): boolean {
|
||||||
|
if (a.familyId && b.familyId) return a.familyId === b.familyId
|
||||||
|
return sameOriginGroup(a.goodName, b.goodName)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user