Skip to content

Commit

Permalink
fix(composables): is in cart condition (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored Aug 20, 2020
1 parent e58bcac commit 37f7b8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/composables/__tests__/useAddToCart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Composables - useAddToCart", () => {

describe("isInCart", () => {
it("should show that product is in cart", () => {
cartItemsMock.value = [{ id: "qwe" }];
cartItemsMock.value = [{ referencedId: "qwe" }];
const { isInCart } = useAddToCart(rootContextMock, {
id: "qwe",
} as any);
Expand All @@ -71,7 +71,7 @@ describe("Composables - useAddToCart", () => {

it("should show that product is not cart", () => {
stateCart.value = {
lineItems: [{ id: "qwert" }],
lineItems: [{ referencedId: "qwert" }],
};
const { isInCart } = useAddToCart(rootContextMock, {
id: "qwe",
Expand Down
6 changes: 4 additions & 2 deletions packages/composables/src/logic/useAddToCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ export const useAddToCart = (

const getStock = computed(() => product && product.stock);

const isInCart = computed((): boolean =>
cartItems.value.some((item: any) => item.id === product.id)
const isInCart = computed(
(): boolean =>
product &&
cartItems.value.some((item: any) => item.referencedId === product.id)
);

return {
Expand Down

0 comments on commit 37f7b8a

Please sign in to comment.