diff --git a/__tests__/jobs.test.js b/__tests__/jobs.test.js index 9cf6d17..4073323 100644 --- a/__tests__/jobs.test.js +++ b/__tests__/jobs.test.js @@ -65,4 +65,27 @@ describe('isSkuInCart', function () { const res5 = await isSkuInCart('5'); expect([res1, res2, res3, res4, res5]).toEqual([[], [], [], ['4'], []]); }); + + test('if cart is empty should return all skuIds', async () => { + fetch.mockImplementation(() => { + return Promise.resolve({ + headers: { + raw: () => { + return {}; + }, + }, + json() { + return { + success: true, + resultData: { + cartInfo: null, + }, + }; + }, + }); + }); + const res1 = await isSkuInCart('1'); + const res2 = await isSkuInCart(['1', '2', '3']); + expect([res1, res2, ]).toEqual([['1'], ['1', '2', '3']]); + }); }); diff --git a/jobs.js b/jobs.js index 835a9f3..2e2480e 100644 --- a/jobs.js +++ b/jobs.js @@ -273,7 +273,7 @@ async function isSkuInCart(skuId, areaId) { if (res.success) { let allskus = []; const allIds = new Set(); - if (!res.resultData.cartInfo) return false; + if (!res.resultData.cartInfo) return skuIds; res.resultData.cartInfo.vendors.forEach(v => { allskus = allskus.concat(v.sorted); }); @@ -288,7 +288,7 @@ async function isSkuInCart(skuId, areaId) { }); return skuIds.filter(s => !allIds.has(s)); } - return []; + return skuIds; } /**