Skip to content

Commit

Permalink
Fix: 购物车为空的时候, 是否在购物车中的判断出错
Browse files Browse the repository at this point in the history
  • Loading branch information
meooxx committed Jan 29, 2021
1 parent 3da77bf commit 10bda0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions __tests__/jobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']]);
});
});
4 changes: 2 additions & 2 deletions jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -288,7 +288,7 @@ async function isSkuInCart(skuId, areaId) {
});
return skuIds.filter(s => !allIds.has(s));
}
return [];
return skuIds;
}

/**
Expand Down

0 comments on commit 10bda0e

Please sign in to comment.