31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
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)
|
|
})
|
|
})
|