Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const addProductToCart = data => (dispatch, getState) => {
const state = getState();
// Transform the options to the required format for the pipeline request.
const options = getAddToCartOptions(state, data);
const { productId, quantity } = data;
dispatch(addProductsToCart([{
productId,
quantity,
...(options) && { options },
}]));
};
export const addProductToCart = data => (dispatch, getState) => {
const state = getState();
// Transform the options to the required format for the pipeline request.
const options = getAddToCartOptions(state, data);
const { productId, quantity } = data;
dispatch(addProductsToCart([{
productId,
quantity,
...(options) && { options },
}]));
};
addToCart: products => dispatch(addProductsToCart(products)),
});
const expected = {
productId: 'product_2',
quantity: 1,
options: [
{ id: '1', type: 'select', value: '4' },
{ id: '3', type: 'select', value: '2' },
],
};
addProductToCart(input)(dispatch, getState);
expect(addProductsToCart).toHaveBeenCalledTimes(1);
expect(addProductsToCart).toHaveBeenCalledWith([expected]);
expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith(addProductsToCart());
});
});