fix(sync): hydrate all origin product details
This commit is contained in:
@@ -276,3 +276,46 @@ describe('SyncService', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('SyncService product detail scopes', () => {
|
||||
const originGoods = [
|
||||
{ id: 1n, sdsGoodId: 'all-1' },
|
||||
{ id: 2n, sdsGoodId: 'all-2' },
|
||||
];
|
||||
|
||||
function createService() {
|
||||
const prisma = {
|
||||
originGood: { findMany: jest.fn().mockResolvedValue(originGoods) },
|
||||
} as unknown as PrismaService;
|
||||
const sds = {
|
||||
fetchProductDetail: jest.fn(async (goodId: string) => ({ id: goodId })),
|
||||
} as unknown as SdsClientService;
|
||||
const scopedService = new SyncService(prisma, sds);
|
||||
jest
|
||||
.spyOn(scopedService as any, 'persistProductDetail')
|
||||
.mockResolvedValue(undefined);
|
||||
return { scopedService, prisma, sds };
|
||||
}
|
||||
|
||||
it('manual detail sync selects every active origin product', async () => {
|
||||
const { scopedService, prisma, sds } = createService();
|
||||
const result = await scopedService.syncAllProductDetails();
|
||||
|
||||
expect(prisma.originGood.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ where: { delisted: false } }),
|
||||
);
|
||||
expect(sds.fetchProductDetail).toHaveBeenCalledTimes(2);
|
||||
expect(result).toEqual({ total: 2, synced: 2, failed: 0 });
|
||||
});
|
||||
|
||||
it('hourly detail refresh remains limited to configured products', async () => {
|
||||
const { scopedService, prisma } = createService();
|
||||
await scopedService.syncConfiguredProductDetails();
|
||||
|
||||
expect(prisma.originGood.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { delisted: false, goods: { some: {} } },
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user