Skip to content

Commit

Permalink
@trivial Remove console.log statements and other debug messages (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
dplaton authored Mar 30, 2020
1 parent ae20b21 commit 0c890ec
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';

import ChangePassword from '../changePassword';
import UserContextProvider, { useUserContext } from '../../../context/UserContext';
import UserContextProvider from '../../../context/UserContext';
import i18n from '../../../../__mocks__/i18nForTests';

import MUTATION_CHANGE_PASSWORD from '../../../queries/mutation_change_password.graphql';
Expand Down
2 changes: 1 addition & 1 deletion react-components/src/components/Checkout/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* governing permissions and limitations under the License.
*
******************************************************************************/
import React, { Fragment, useCallback } from 'react';
import React, { Fragment } from 'react';
import { shape, string } from 'prop-types';

import { Price } from '@magento/peregrine';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('<CreateAccount>', () => {
<I18nextProvider i18n={i18n}>
<MockedProvider>
<UserContextProvider>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => (state, action) => state}>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => state => state}>
<CreateAccount showMyAccount={jest.fn()} />
</CartProvider>
</UserContextProvider>
Expand Down Expand Up @@ -128,7 +128,6 @@ describe('<CreateAccount>', () => {
const ContextWrapper = () => {
const [{ isSignedIn, currentUser }] = useUserContext();
let content;
console.log(`is signed in? ${isSignedIn}`);
if (isSignedIn && currentUser.firstname) {
content = <div data-testid="success">{currentUser.firstname}</div>;
} else {
Expand All @@ -141,7 +140,7 @@ describe('<CreateAccount>', () => {
const { getByLabelText, getByTestId, container } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserContextProvider>
<CartProvider initialState={{ cartId: 'guest123' }} reducerFactory={() => (state, action) => state}>
<CartProvider initialState={{ cartId: 'guest123' }} reducerFactory={() => state => state}>
<ContextWrapper />
</CartProvider>
</UserContextProvider>
Expand Down Expand Up @@ -225,7 +224,7 @@ describe('<CreateAccount>', () => {
const { getByTestId, getByLabelText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserContextProvider>
<CartProvider initialState={{ cartId: 'guest123' }} reducerFactory={() => (state, action) => state}>
<CartProvider initialState={{ cartId: 'guest123' }} reducerFactory={() => state => state}>
<ContextWrapper />
</CartProvider>
</UserContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export default () => {
password
} = formValues;
try {
console.log(`[CreateAccount] Create account...`);
//1. Create the account
const {
data: {
createCustomer: { customer }
Expand All @@ -54,15 +52,12 @@ export default () => {

//2. Generate the customer token.
// Most of the commerce solutions DO NOT sign in the user after the account is created.
// We must think of splitting this process
console.log(`[CreateAccount] Done creating account, generate user token...`);
const { data: customerTokenData } = await generateCustomerToken({
variables: { email: customer.email, password }
});
const token = customerTokenData.generateCustomerToken.token;

//3. Set the token in the cookie now because subsequent requests would need it
console.log(`[CreateAccount] Done generating token, let's get out ${token}`);
setUserCookie(token);
setToken(token);

Expand All @@ -77,7 +72,6 @@ export default () => {
}
});
const mergedCartId = mergeCartsData.mergeCarts.id;
console.log(`[CreateAccount] Carts are merged, ${mergedCartId} is the new cart id`);

//5. Dispatch the action to update the user state
setCartCookie(mergedCartId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ describe('CartContext', () => {
};

const renderAndGetResult = action => {
const { getByRole, debug, getByTestId } = render(
const { getByRole, getByTestId } = render(
<CartProvider>
<MockConsumer action={action} />
</CartProvider>
);

fireEvent.click(getByRole('button'));
debug();
const stateNode = getByTestId('state');
return stateNode.textContent;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CartInitializer from '../cartInitializer';

describe('Cart handlers', () => {
const aSpy = jest.fn();
const mockReducerFactory = fn => {
const mockReducerFactory = () => {
return (state, action) => {
switch (action.type) {
case 'cartId':
Expand Down Expand Up @@ -78,9 +78,9 @@ describe('Cart handlers', () => {
);
};

const { getByTestId, getByRole, debug } = render(renderWithContext(MockComponent));
const { getByTestId, getByRole } = render(renderWithContext(MockComponent));
fireEvent.click(getByRole('button'));
const cartElement = await waitForElement(() => getByTestId('cart-id'));
await waitForElement(() => getByTestId('cart-id'));
expect(aSpy).toHaveBeenCalledWith('open');
});

Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Cart handlers', () => {
const { getByTestId, getByRole } = render(renderWithContext(MockComponent));

fireEvent.click(getByRole('button'));
const cartElement = await waitForElement(() => getByTestId('cart-id'));
await waitForElement(() => getByTestId('cart-id'));
expect(aSpy).toHaveBeenCalledWith('endLoading');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ describe('<CartInitializer />', () => {
if (cartId === 'guest123') {
return <div data-testid="cart-id">customercart</div>;
}
console.log(document.cookie);
return (
<div>
<button
onClick={() => {
console.log(`Reset`);
dispatch({ type: 'reset' });
}}>
Reset
Expand Down
10 changes: 3 additions & 7 deletions react-components/src/components/Minicart/cartInitializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
******************************************************************************/
import { useEffect } from 'react';
import { useCartState } from './cartContext';
import { useCookieValue, useAwaitQuery } from '../../utils/hooks';
import { useMutation, useApolloClient } from '@apollo/react-hooks';
import { useCookieValue } from '../../utils/hooks';
import { useMutation } from '@apollo/react-hooks';
import { useUserContext } from '../../context/UserContext';

import parseError from '../../utils/parseError';
Expand All @@ -27,7 +27,7 @@ import MUTATION_ADD_COUPON from '../../queries/mutation_add_coupon.graphql';
import MUTATION_REMOVE_COUPON from '../../queries/mutation_remove_coupon.graphql';

const CartInitializer = props => {
const [{ cartId: stateCartId }, dispatch] = useCartState();
const [, dispatch] = useCartState();
const [{ cartId: registeredCartId }] = useUserContext();

const CART_COOKIE = 'cif.cart';
Expand Down Expand Up @@ -112,20 +112,16 @@ const CartInitializer = props => {
};
};

console.log(`Cart id from cookie is now ${cartId}, state is ${stateCartId}`);
useEffect(() => {
if (cartId && cartId.length > 0) {
console.log(`Running the effect that puts the cart id ${cartId} in the state`);
dispatch({ type: 'cartId', cartId, methods: createCartHandlers(cartId, dispatch) });
}
}, [cartId]);

useEffect(() => {
if (!registeredCartId && (cartId === null || cartId.length === 0)) {
console.log(`Running the effect with the cart id`);
(async function() {
const { data } = await createCart();
console.log(`Created empty cart ${data.createEmptyCart}`);
setCartCookie(data.createEmptyCart);
dispatch({
type: 'cartId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('<SignIn>', () => {
<I18nextProvider i18n={i18n}>
<MockedProvider>
<UserContextProvider>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => (state, action) => state}>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => state => state}>
<SignIn
showMyAccount={jest.fn()}
showCreateAccount={jest.fn()}
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('<SignIn>', () => {
const { getByTestId, getByLabelText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserContextProvider>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => (state, action) => state}>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => state => state}>
<SignInWrapper />
</CartProvider>
</UserContextProvider>
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('<SignIn>', () => {
const { getByText, getByLabelText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserContextProvider>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => (state, action) => state}>
<CartProvider initialState={{ cartId: null }} reducerFactory={() => state => state}>
<SignIn
showMyAccount={jest.fn()}
showForgotPassword={jest.fn()}
Expand Down
1 change: 0 additions & 1 deletion react-components/src/components/SignIn/useSignin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const useSignin = () => {
}
});
const mergedCartId = mergeCartsData.mergeCarts.id;
console.log(`[SignIn] Carts are merged, ${mergedCartId} is the new cart id`);

//4. set the cart id in the cookie
setCartCookie(mergedCartId);
Expand Down
5 changes: 0 additions & 5 deletions react-components/src/context/UserContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const UserContext = React.createContext();

const reducerFactory = () => {
return (state, action) => {
console.log(`[UserContext] Dispatched action`, action);
switch (action.type) {
case 'setUserDetails':
return {
Expand Down Expand Up @@ -121,8 +120,6 @@ const UserContextProvider = props => {
const [revokeCustomerToken] = useMutation(MUTATION_REVOKE_TOKEN);
const fetchCustomerDetails = useAwaitQuery(QUERY_CUSTOMER_DETAILS);

console.log(`[UserContext] Rendering the user context `, userState);

const setToken = token => {
setUserCookie(token);
dispatch({ type: 'setToken', token });
Expand Down Expand Up @@ -153,9 +150,7 @@ const UserContextProvider = props => {

const getUserDetails = useCallback(async () => {
try {
console.log(`Retrieve details...`);
const { data: customerData } = await fetchCustomerDetails({ fetchPolicy: 'no-cache' });
console.log(`Got customer details `, customerData);
dispatch({ type: 'setUserDetails', userDetails: customerData.customer });
} catch (error) {
dispatch({ type: 'error', error });
Expand Down

0 comments on commit 0c890ec

Please sign in to comment.