feat(product-family): replace legacy good merge with family mechanism in config view and public detail
This commit is contained in:
@@ -92,26 +92,59 @@ describe('PublicService family block (PUBLIC_DETAIL_FROM_FAMILY)', () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
|
||||
it('开关关闭:响应完全不含 family 键(与现状形状一致)', async () => {
|
||||
it('默认(未设开关):输出族块', async () => {
|
||||
delete process.env.PUBLIC_DETAIL_FROM_FAMILY
|
||||
const detail = await service.getGood(sdsGoodId);
|
||||
expect(detail.goodId).toBe(sdsGoodId);
|
||||
expect(detail.family).toBeTruthy();
|
||||
expect(detail.family!.familyCode).toBe(`PF${stamp}`);
|
||||
expect(detail.family!.minPrice).toBe('25');
|
||||
// 旧字段保留(向后兼容)
|
||||
expect(detail.variants.length).toBe(1);
|
||||
});
|
||||
|
||||
it('显式关闭(false):响应完全不含 family 键(应急回退)', async () => {
|
||||
process.env.PUBLIC_DETAIL_FROM_FAMILY = 'false';
|
||||
const detail = await service.getGood(sdsGoodId);
|
||||
expect(detail.goodId).toBe(sdsGoodId);
|
||||
expect('family' in detail).toBe(false);
|
||||
});
|
||||
|
||||
it('开关开启:输出族块(物化矩阵 + 并集 + 起价)', async () => {
|
||||
it('族变体并集:任何族成员链接的 sdsGoodId 均命中同一商品且变体含全体成员', async () => {
|
||||
process.env.PUBLIC_DETAIL_FROM_FAMILY = 'true';
|
||||
const detail = await service.getGood(sdsGoodId);
|
||||
expect(detail.family).not.toBeNull();
|
||||
expect(detail.family!.familyCode).toBe(`PF${stamp}`);
|
||||
expect(detail.family!.familyId).toBe(familyId.toString());
|
||||
expect(detail.family!.crafts).toEqual(['单面印花']);
|
||||
expect(detail.family!.logistics).toEqual(['包邮']);
|
||||
expect(detail.family!.priceMatrix).toBeTruthy();
|
||||
expect(detail.family!.minPrice).toBe('25');
|
||||
// 旧字段保留(向后兼容)
|
||||
expect(detail.variants.length).toBe(1);
|
||||
expect(detail.sizeChart).toBeDefined();
|
||||
// 再加一个同族成员(不同仓库段)
|
||||
const og2 = await prisma.originGood.create({
|
||||
data: {
|
||||
sdsGoodId: `pubfam-m-${stamp}`,
|
||||
goodName: `美国(包邮)测试T恤-PF${stamp}-单面印花-二仓`,
|
||||
craftLabel: '单面印花',
|
||||
logisticsLabel: '包邮',
|
||||
familyId,
|
||||
},
|
||||
});
|
||||
createdOriginGoodIds.push(og2.id);
|
||||
await prisma.originGoodVariant.create({
|
||||
data: {
|
||||
originGoodId: og2.id,
|
||||
sdsVariantId: 'pf-m-v1',
|
||||
sku: `PF-${stamp}-M`,
|
||||
sizeId: 'size_M',
|
||||
sizeName: 'M',
|
||||
colorId: 'color_blk',
|
||||
colorName: '黑色',
|
||||
price: new Prisma.Decimal(26),
|
||||
},
|
||||
});
|
||||
|
||||
// 用成员链接(非主链接)的 sdsGoodId 访问 → 命中同一商品(响应 goodId 仍为主链接)
|
||||
const detail = await service.getGood(`pubfam-m-${stamp}`);
|
||||
expect(detail.goodId).toBe(sdsGoodId);
|
||||
const skus = detail.variants.map((v) => v.sku);
|
||||
expect(skus).toContain(`PF-${stamp}-S`);
|
||||
expect(skus).toContain(`PF-${stamp}-M`); // 族成员变体并集
|
||||
// 清理:把成员移出族避免影响其他用例
|
||||
await prisma.originGoodVariant.deleteMany({ where: { originGoodId: og2.id } });
|
||||
await prisma.originGood.update({ where: { id: og2.id }, data: { familyId: null } });
|
||||
});
|
||||
|
||||
it('无族商品:开关开启也不含 family 键', async () => {
|
||||
|
||||
Reference in New Issue
Block a user