Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into 20201211-reduce-total…
Browse files Browse the repository at this point in the history
…-blocking-time
  • Loading branch information
filipsobol committed Dec 22, 2020
2 parents 8d7db3b + 0e8b7b4 commit 1ba2b22
Show file tree
Hide file tree
Showing 79 changed files with 546 additions and 642 deletions.
4 changes: 2 additions & 2 deletions packages/boilerplate/theme/pages/Checkout/Payment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default {
const { billingDetails, shippingDetails, paymentMethods, chosenPaymentMethod } = useCheckout();
const sameAsShipping = ref(false);
const { billing, load: loadBilling, setDefault } = useUserBilling();
const { billing, load: loadUserBilling, setDefault } = useUserBilling();
const { isAuthenticated } = useUser();
const canAddNewAddress = ref(true);
Expand Down Expand Up @@ -246,7 +246,7 @@ export default {
onMounted(async () => {
if (isAuthenticated.value) {
await loadBilling();
await loadUserBilling();
const billingAddresses = userBillingGetters.getAddresses(billing.value);
if (!billingAddresses || !billingAddresses.length) {
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/boilerplate/theme/pages/Checkout/Shipping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default {
shippingMethods
} = useCheckout();
const { shipping, load: loadShipping, setDefault } = useUserShipping();
const { shipping, load: loadUserShipping, setDefault } = useUserShipping();
const { isAuthenticated } = useUser();
const canAddNewAddress = ref(true);
Expand Down Expand Up @@ -246,7 +246,7 @@ export default {
onMounted(async () => {
if (isAuthenticated.value) {
await loadShipping();
await loadUserShipping();
const shippingAddresses = userShippingGetters.getAddresses(shipping.value);
if (!shippingAddresses || !shippingAddresses.length) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import getOrders from '../../src/api/getMyOrders';
import defaultQuery from '../../src/api/getMyOrders/defaultQuery';
import getOrders from '../../src/api/getOrders';
import defaultQuery from '../../src/api/getOrders/defaultQuery';
import { OrderWhereSearch } from '../../src/types/Api';

describe('[commercetools-api-client] getMyOrders', () => {
describe('[commercetools-api-client] getOrders', () => {
const params: OrderWhereSearch = {
id: 'fvdrt8gaw4r',
limit: 10,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gql from 'graphql-tag';
import { OrderFragment } from './../../fragments';
import { OrderFragment } from '../../fragments';

export default gql`
${OrderFragment}
Expand Down
2 changes: 1 addition & 1 deletion packages/commercetools/api-client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export { default as customerUpdateMe } from './customerUpdateMe';
export { default as getCart } from './getCart';
export { default as getCategory } from './getCategory';
export { default as getMe } from './getMe';
export { default as getMyOrders } from './getMyOrders';
export { default as getOrders } from './getOrders';
export { default as getProduct } from './getProduct';
export { default as getShippingMethods } from './getShippingMethods';
export { default as isGuest } from './isGuest';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCart } from './../../src/useCart';
import useCart from './../../src/useCart';
import loadCurrentCart from './../../src/useCart/currentCart';

const context = {
Expand All @@ -17,9 +17,7 @@ const context = {

jest.mock('./../../src/useCart/currentCart');
jest.mock('@vue-storefront/core', () => ({
useCartFactory: (params) => ({
useCart: () => params
})
useCartFactory: (params) => () => params
}));

const customQuery = undefined;
Expand All @@ -29,53 +27,35 @@ describe('[commercetools-composables] useCart', () => {
jest.clearAllMocks();
});

// it('loads current cart when there is user session', async () => {
// (isTokenUserSession as any).mockReturnValue(true);
// const { loadCart } = useCart() as any;

// loadCart();

// expect(loadCurrentCart).toBeCalled();
// });

// it('does not loads cart without user session', async () => {
// (isTokenUserSession as any).mockReturnValue(false);
// const { loadCart } = useCart() as any;

// loadCart();

// expect(loadCurrentCart).not.toBeCalled();
// });

it('adds to cart', async () => {
const { addToCart } = useCart() as any;
const response = await addToCart(context, { currentCart: 'current cart', product: 'product1', quantity: 3 });
const { addItem } = useCart() as any;
const response = await addItem(context, { currentCart: 'current cart', product: 'product1', quantity: 3 });

expect(response).toEqual('some cart');
expect(context.$ct.api.addToCart).toBeCalledWith('current cart', 'product1', 3, customQuery);
});

it('creates a new cart and add an item', async () => {
const { addToCart } = useCart() as any;
const { addItem } = useCart() as any;
(loadCurrentCart as any).mockReturnValue('some cart');
const response = await addToCart(context, { currentCart: null, product: 'product1', quantity: 3 });
const response = await addItem(context, { currentCart: null, product: 'product1', quantity: 3 });
expect(loadCurrentCart).toBeCalled();

expect(response).toEqual('some cart');
expect(context.$ct.api.addToCart).toBeCalledWith('some cart', 'product1', 3, customQuery);
});

it('removes from cart', async () => {
const { removeFromCart } = useCart() as any;
const response = await removeFromCart(context, { currentCart: 'current cart', product: 'product1' });
const { removeItem } = useCart() as any;
const response = await removeItem(context, { currentCart: 'current cart', product: 'product1' });

expect(response).toEqual('some cart');
expect(context.$ct.api.removeFromCart).toBeCalledWith('current cart', 'product1', customQuery);
});

it('updates quantity', async () => {
const { updateQuantity } = useCart() as any;
const response = await updateQuantity(context, {
const { updateItemQty } = useCart() as any;
const response = await updateItemQty(context, {
currentCart: 'current cart',
product: { name: 'product1' },
quantity: 5
Expand All @@ -86,8 +66,8 @@ describe('[commercetools-composables] useCart', () => {
});

it('clears cart', async () => {
const { clearCart } = useCart() as any;
const response = await clearCart(context, { currentCart: 'current cart' });
const { clear } = useCart() as any;
const response = await clear(context, { currentCart: 'current cart' });

expect(response).toEqual('current cart');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const resetFields = () => {
};
};

const loadCart = jest.fn();
const load = jest.fn();
const setCart = jest.fn((newCart) => {
cart.value = newCart;
});
const cartFields = { cart, loadCart };
const cartFields = { cart, load };

jest.mock('./../../src/useCart', jest.fn(() => ({
useCart: () => cartFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ describe('[commercetools-composables] useProduct', () => {

const response = await productsSearch(context, { id: 'product-id' });

expect(response).toEqual({
data: [product('prod1', 'prod-1', 'xxx1'), product('prod2', 'prod-2', 'xxx2')],
total: 54
});
expect(response).toEqual([product('prod1', 'prod-1', 'xxx1'), product('prod2', 'prod-2', 'xxx2')]);
expect(context.$ct.api.getProduct).toBeCalledWith({ id: 'product-id' }, undefined);
expect(enhanceProducts).toBeCalledWith(productResponse);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { params } from '../../src/useUser/factoryParams';
import { authenticate } from '../../src/useUser/authenticate';
import { useCart } from '../../src/useCart';
import useCart from '../../src/useCart';

jest.mock('../../src/useCart', () => ({
useCart: jest.fn(() => {})
}));
jest.mock('../../src/useCart', () => jest.fn(() => {}));

jest.mock('../../src/useUser/authenticate', () => ({
authenticate: jest.fn()
Expand Down Expand Up @@ -36,56 +34,56 @@ const context = {
} as any;

describe('[commercetools-composables] factoryParams', () => {
it('loadUser return customer data', async () => {
it('load return customer data', async () => {

(context.$ct.api.getMe as jest.Mock).mockReturnValueOnce({ data: { me: { customer } }});
expect(await params.loadUser(context)).toEqual(customer);
expect(await params.load(context as any)).toEqual(customer);

(context.$ct.api.getMe as jest.Mock).mockReturnValueOnce({ data: { me: { customer: null } }});
expect(await params.loadUser(context)).toEqual(null);
expect(await params.load(context)).toEqual(null);
});

it('does not loading the user without user session', async () => {
(context.$ct.api.isGuest as any).mockReturnValue(true);
expect(await params.loadUser(context)).toEqual(null);
expect(await params.load(context as any)).toEqual(null);
});

it('logOut method calls API log out method', async () => {
(context.$ct.api.createCart as jest.Mock).mockReturnValueOnce({ data: { cart: {} }});
(useCart as jest.Mock).mockReturnValueOnce({refreshCart: refreshCartMock});
await params.logOut(context);
await params.logOut(context as any);
expect(context.$ct.api.customerSignOut).toHaveBeenCalled();
});

it('updateUser return updated user', async () => {
const user = {currentUser: 'Jon', updatedUserData: 'Bob'} as any;
(context.$ct.api.customerUpdateMe as jest.Mock).mockReturnValueOnce({ user });
expect(await params.updateUser(context, user)).toEqual(user);
expect(await params.updateUser(context as any, user)).toEqual(user);
});

it('updates the user and loads when it is not available', async () => {
const user = {currentUser: null, updatedUserData: 'Bob'} as any;
(context.$ct.api.getMe as jest.Mock).mockReturnValueOnce({ data: { me: user } });

(context.$ct.api.customerUpdateMe as jest.Mock).mockReturnValueOnce({ user });
expect(await params.updateUser(context, user)).toEqual(user);
expect(await params.updateUser(context as any, user)).toEqual(user);
});

it('register method return a new customer', async () => {
(authenticate as jest.Mock).mockReturnValueOnce({ customer });
expect(await params.register(context, customer)).toEqual(customer);
expect(await params.register(context as any, customer)).toEqual(customer);
});

it('logIn method return a logged in customer', async () => {
(useCart as jest.Mock).mockReturnValueOnce({refreshCart: refreshCartMock});
(authenticate as jest.Mock).mockReturnValueOnce({ customer });
expect(await params.logIn(context, customer)).toEqual(customer);
expect(await params.logIn(context as any, customer)).toEqual(customer);
});

describe('changePassword', () => {
it('register method return a new customer', async () => {
(authenticate as jest.Mock).mockReturnValueOnce({ customer });
expect(await params.register(context, customer)).toEqual(customer);
expect(await params.register(context as any, customer)).toEqual(customer);
});

it('succeed returning logged user', async () => {
Expand All @@ -97,7 +95,7 @@ describe('[commercetools-composables] factoryParams', () => {
(context.$ct.api.customerChangeMyPassword as jest.Mock).mockReturnValueOnce({ data: { user: customer }});
(authenticate as jest.Mock).mockReturnValueOnce({ customer, cart });

expect(await params.changePassword(context, changePasswordParams)).toEqual(customer);
expect(await params.changePassword(context as any, changePasswordParams)).toEqual(customer);
expect(context.$ct.api.customerSignOut).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jest.mock('@vue-storefront/core', () => ({
useUserFactory: jest.fn(() => ({ useUser: () => ({ user: 'api'}) }))
useUserFactory: jest.fn(() => () => ({ user: 'api'}))
}));

jest.mock('../../src/useUser/factoryParams', () => ({
Expand All @@ -8,7 +8,7 @@ jest.mock('../../src/useUser/factoryParams', () => ({

import { useUserFactory } from '@vue-storefront/core';
import { params } from '../../src/useUser/factoryParams';
import { useUser } from '../../src/useUser';
import useUser from '../../src/useUser';

describe('[commercetools-composables] useUser', () => {
it('returns useUserFactory functions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('@vue-storefront/commercetools-api', () => ({
}));

jest.mock('@vue-storefront/core', () => ({
useUserOrdersFactory: (params) => () => params
useUserOrdersFactory: ({ searchOrders }) => () => ({ search: searchOrders })
}));

const context = {
Expand All @@ -34,40 +34,31 @@ describe('[commercetools-composables] useUserOrders', () => {
});

it('loads user orders with criteria', async () => {
const { searchOrders } = useUserOrders() as any;
const { search } = useUserOrders() as any;

const response = await searchOrders(context, { param: 'param1' });
const response = await search(context, { param: 'param1' });

expect(response).toEqual({
data: ['order1', 'order2', 'order3'],
total: 3
});
expect(response).toEqual(['order1', 'order2', 'order3']);
expect(context.$ct.api.getOrders).toBeCalledWith({ param: 'param1' }, undefined);
});

it('loads user all orders', async () => {
const { searchOrders } = useUserOrders() as any;
const { search } = useUserOrders() as any;

const response = await searchOrders(context);
const response = await search(context);

expect(response).toEqual({
data: ['order1', 'order2', 'order3'],
total: 3
});
expect(response).toEqual(['order1', 'order2', 'order3']);
expect(context.$ct.api.getOrders).toBeCalled();
});

it('loads user orders with empty response', async () => {
(context.$ct.api.getOrders as jest.Mock).mockReturnValue({ data: null });

const { searchOrders } = useUserOrders() as any;
const { search } = useUserOrders() as any;

const response = await searchOrders(context, { param: 'param1' });
const response = await search(context, { param: 'param1' });

expect(response).toEqual({
data: [],
total: 0
});
expect(response).toEqual([]);
expect(context.$ct.api.getOrders).toBeCalledWith({ param: 'param1' }, undefined);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/commercetools/composables/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import useCategory from './useCategory';
import useProduct from './useProduct';
import { useCart } from './useCart';
import useCart from './useCart';
import useCheckout from './useCheckout';
import { useUser } from './useUser';
import useUser from './useUser';
import useUserOrders from './useUserOrders';
import { useReview } from './useReview';
import useFacet from './useFacet';
Expand Down
Loading

0 comments on commit 1ba2b22

Please sign in to comment.