feat(public): merge secondary media gallery images with URL dedup

This commit is contained in:
yeuimu
2026-08-28 11:19:27 +08:00
parent 457792b729
commit d826c5bdd4
2 changed files with 37 additions and 1 deletions
@@ -435,6 +435,7 @@ describe('PublicService', () => {
sizeChart: { rows: [{ sizeName: 'S', measurements: [{ key: 'chest', cm: '94' }] }, { sizeName: 'M', measurements: [{ key: 'chest', cm: '100' }] }] },
packageSpecs: { rows: [{ sizeName: 'S' }] },
options: { sizes: [{ name: 'S' }, { name: 'M' }] },
media: { images: ['http://img/pri-a', 'http://img/pri-b'], primaryImageUrl: 'http://img/pri-a' },
},
});
// Secondary: duplicate Black|S with a DIFFERENT price (must be dropped,
@@ -451,6 +452,7 @@ describe('PublicService', () => {
sizeChart: { rows: [{ sizeName: 'XXXL', measurements: [{ key: 'chest', cm: '120' }] }] },
packageSpecs: { rows: [{ sizeName: 'M' }, { sizeName: 'XXXL' }] },
options: { sizes: [{ name: 'XXXL' }] },
media: { images: ['http://img/pri-a', 'http://img/sec-x'], primaryImageUrl: 'http://img/pri-a' },
},
});
const mergedGood = await prisma.good.create({
@@ -483,6 +485,11 @@ describe('PublicService', () => {
// Options: sizes unioned S/M + XXXL.
const optSizes = (detail.options as any).sizes.map((s: any) => s.name).sort();
expect(optSizes).toEqual(['M', 'S', 'XXXL']);
// Media gallery: primary images first, secondary-only URL appended,
// duplicate URL (pri-a) kept once.
const media = detail.media as any;
expect(media.images).toEqual(['http://img/pri-a', 'http://img/pri-b', 'http://img/sec-x']);
expect(media.primaryImageUrl).toBe('http://img/pri-a');
} finally {
await prisma.goodOriginGood.deleteMany({ where: { goodId: mergedGood.id } });
await prisma.good.delete({ where: { id: mergedGood.id } });