Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "PWA-3273:Get Minimum Password Length from configuration" #4324

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert "PWA-3273:Get Minimum Password Length from configuration (#4319)"
This reverts commit 8ec82f7.
glo82145 authored Sep 19, 2024

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
commit 823bf00f4ccad6831f5415d874f4692624819ac1
8 changes: 2 additions & 6 deletions packages/peregrine/lib/store/actions/user/asyncActions.js
Original file line number Diff line number Diff line change
@@ -63,17 +63,13 @@ export const resetPassword = ({ email }) =>
dispatch(actions.resetPassword.receive());
};

export const setToken = (token, customerAccessTokenLifetime = 1) =>
export const setToken = (token, customer_token_lifetime = 3600) =>
async function thunk(...args) {
const [dispatch] = args;

// Store token in local storage.
// TODO: Get correct token expire time from API
storage.setItem(
'signin_token',
token,
customerAccessTokenLifetime * 3600
);
storage.setItem('signin_token', token, customer_token_lifetime);

// Persist in store
dispatch(actions.setToken(token));
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`errros should render properly 1`] = `
Map {
"createAccountQuery" => "Create Account Mutation Error",
"signInMutation" => "Sign In Mutation Error",
}
`;

exports[`handle submit event creates an account, dispatches event, signs in, and generates a new cart 1`] = `
Object {
"payload": Object {
@@ -19,30 +12,6 @@ Object {
}
`;

exports[`handle submit event should dispatch create account event 1`] = `
Object {
"payload": Object {
"email": "[email protected]",
"firstName": "Bender",
"isSubscribed": false,
"lastName": "Rodriguez",
},
"type": "USER_CREATE_ACCOUNT",
}
`;

exports[`handleSubmit should dispatch create account event 1`] = `
Object {
"payload": Object {
"email": "[email protected]",
"firstName": "Bender",
"isSubscribed": false,
"lastName": "Rodriguez",
},
"type": "USER_CREATE_ACCOUNT",
}
`;

exports[`returns the correct shape 1`] = `
Object {
"errors": Map {
@@ -60,7 +29,6 @@ Object {
},
"isDisabled": false,
"recaptchaWidgetProps": Object {},
"minimumPasswordLength":8
}
`;

@@ -81,28 +49,5 @@ Object {
},
"isDisabled": false,
"recaptchaWidgetProps": Object {},
minimumPasswordLength:8
}
`;

exports[`should return properly 1`] = `
Object {
"errors": Map {
"createAccountQuery" => null,
"signInMutation" => null,
},
"handleEnterKeyPress": [Function],
"handleSubmit": [Function],
"initialValues": Object {
"customer": Object {
"email": "[email protected]",
"firstname": "Gooseton",
"lastname": "Jr",
},
"userName": "gooseton",
},
"isDisabled": false,
"minimumPasswordLength": 8,
"recaptchaWidgetProps": Object {},
}
`;

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
import { GET_STORE_CONFIG_DATA } from '../../CreateAccount/createAccount.gql';

export const CREATE_ACCOUNT = gql`
mutation CreateAccountAfterCheckout(
@@ -45,6 +44,7 @@ export const SIGN_IN = gql`
mutation SignInAfterCheckout($email: String!, $password: String!) {
generateCustomerToken(email: $email, password: $password) {
token
customer_token_lifetime
}
}
`;
@@ -111,6 +111,5 @@ export default {
createCartMutation: CREATE_CART,
getCartDetailsQuery: GET_CART_DETAILS,
getCustomerQuery: GET_CUSTOMER,
signInMutation: SIGN_IN,
getStoreConfigQuery: GET_STORE_CONFIG_DATA
signInMutation: SIGN_IN
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo, useState } from 'react';
import { useMutation, useQuery } from '@apollo/client';
import { useMutation } from '@apollo/client';

import mergeOperations from '../../../util/shallowMerge';
import { useUserContext } from '../../../context/user';
@@ -39,8 +39,7 @@ export const useCreateAccount = props => {
createCartMutation,
getCartDetailsQuery,
getCustomerQuery,
signInMutation,
getStoreConfigQuery
signInMutation
} = operations;
const [isSubmitting, setIsSubmitting] = useState(false);
const [, { createCart, getCartDetails, removeCart }] = useCartContext();
@@ -66,23 +65,6 @@ export const useCreateAccount = props => {
fetchPolicy: 'no-cache'
});

const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first'
});

const {
minimumPasswordLength,
customerAccessTokenLifetime
} = useMemo(() => {
const storeConfig = storeConfigData?.storeConfig || {};

return {
minimumPasswordLength: storeConfig.minimum_password_length,
customerAccessTokenLifetime:
storeConfig.customer_access_token_lifetime
};
}, [storeConfigData]);
const fetchUserDetails = useAwaitQuery(getCustomerQuery);
const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);

@@ -135,8 +117,12 @@ export const useCreateAccount = props => {
...recaptchaDataForSignIn
});
const token = signInResponse.data.generateCustomerToken.token;
await (customerAccessTokenLifetime
? setToken(token, customerAccessTokenLifetime)
const customerTokenLifetime =
signInResponse.data.generateCustomerToken
.customer_token_lifetime;

await (customerTokenLifetime
? setToken(token, customerTokenLifetime)
: setToken(token));

// Clear guest cart from redux.
@@ -166,7 +152,6 @@ export const useCreateAccount = props => {
}
},
[
customerAccessTokenLifetime,
createAccount,
createCart,
fetchCartDetails,
@@ -215,7 +200,6 @@ export const useCreateAccount = props => {
handleEnterKeyPress,
isDisabled: isSubmitting || isGettingDetails || recaptchaLoading,
initialValues: sanitizedInitialValues,
recaptchaWidgetProps,
minimumPasswordLength
recaptchaWidgetProps
};
};
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@ Object {
"userName": "gooseton",
},
"isDisabled": false,
"minimumPasswordLength": 8,
"recaptchaWidgetProps": Object {},
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useMutation, useQuery, useApolloClient } from '@apollo/client';
import { useMutation, useApolloClient } from '@apollo/client';
import { act } from 'react-test-renderer';

import { useCartContext } from '../../../context/cart';
@@ -16,8 +16,7 @@ jest.mock('@apollo/client', () => {
return {
...apolloClient,
useMutation: jest.fn().mockReturnValue([jest.fn()]),
useApolloClient: jest.fn(),
useQuery: jest.fn()
useApolloClient: jest.fn()
};
});
jest.mock('../../../../lib/hooks/useAwaitQuery', () => ({
@@ -92,17 +91,7 @@ const createAccountMutation = 'createAccountMutation';
const createCartMutation = 'createCartMutation';
const signInMutation = 'signInMutation';
const mergeCartsMutation = 'mergeCartsMutation';
const getStoreConfigQuery = 'getStoreConfigQuery';

const getStoreConfigQueryFn = jest.fn().mockReturnValue({
data: {
storeConfig: {
store_code: 'default',
minimum_password_length: 8,
customer_access_token_lifetime: 1
}
}
});

const customerQueryFn = jest.fn();
const getCartDetailsQueryFn = jest.fn();
const createAccountMutationFn = jest
@@ -113,7 +102,8 @@ const signInMutationFn = jest.fn().mockReturnValue([
jest.fn().mockReturnValue({
data: {
generateCustomerToken: {
token: 'customer token'
token: 'customer token',
customer_token_lifetime: 3600
}
}
}),
@@ -130,7 +120,6 @@ const defaultProps = {
getCartDetailsQuery,
getCustomerQuery,
mergeCartsMutation,
getStoreConfigQuery,
signInMutation
},
initialValues: {
@@ -154,13 +143,6 @@ const defaultFormValues = {
};

beforeAll(() => {
useQuery.mockImplementation(query => {
if (query === getStoreConfigQuery) {
return getStoreConfigQueryFn();
} else {
return [jest.fn(), {}];
}
});
useAwaitQuery.mockImplementation(query => {
if (query === getCustomerQuery) {
return customerQueryFn();
@@ -291,11 +273,12 @@ describe('handleSubmit', () => {

test('should signin after account creation', async () => {
const token = 'customertoken';
const customer_token_lifetime = 1;
const customer_token_lifetime = 3600;
const signIn = jest.fn().mockReturnValue({
data: {
generateCustomerToken: {
token
token,
customer_token_lifetime
}
}
});
14 changes: 2 additions & 12 deletions packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ export const SIGN_IN = gql`
mutation SignInAfterCreate($email: String!, $password: String!) {
generateCustomerToken(email: $email, password: $password) {
token
customer_token_lifetime
}
}
`;
@@ -125,23 +126,12 @@ export const MERGE_CARTS = gql`
}
${CheckoutPageFragment}
`;
export const GET_STORE_CONFIG_DATA = gql`
query GetStoreConfigData {
# eslint-disable-next-line @graphql-eslint/require-id-when-available
storeConfig {
store_code
minimum_password_length
customer_access_token_lifetime
}
}
`;

export default {
createAccountMutation: CREATE_ACCOUNT,
createCartMutation: CREATE_CART,
getCartDetailsQuery: GET_CART_DETAILS,
getCustomerQuery: GET_CUSTOMER,
mergeCartsMutation: MERGE_CARTS,
signInMutation: SIGN_IN,
getStoreConfigQuery: GET_STORE_CONFIG_DATA
signInMutation: SIGN_IN
};
35 changes: 8 additions & 27 deletions packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo, useState } from 'react';
import { useApolloClient, useMutation, useQuery } from '@apollo/client';
import { useApolloClient, useMutation } from '@apollo/client';

import mergeOperations from '../../util/shallowMerge';
import { useUserContext } from '../../context/user';
@@ -37,8 +37,7 @@ export const useCreateAccount = props => {
getCartDetailsQuery,
getCustomerQuery,
mergeCartsMutation,
signInMutation,
getStoreConfigQuery
signInMutation
} = operations;
const apolloClient = useApolloClient();
const [isSubmitting, setIsSubmitting] = useState(false);
@@ -70,24 +69,6 @@ export const useCreateAccount = props => {
fetchPolicy: 'no-cache'
});

const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first'
});

const {
minimumPasswordLength,
customerAccessTokenLifetime
} = useMemo(() => {
const storeConfig = storeConfigData?.storeConfig || {};

return {
minimumPasswordLength: storeConfig.minimum_password_length,
customerAccessTokenLifetime:
storeConfig.customer_access_token_lifetime
};
}, [storeConfigData]);

const fetchUserDetails = useAwaitQuery(getCustomerQuery);
const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);

@@ -155,8 +136,11 @@ export const useCreateAccount = props => {
...recaptchaDataForSignIn
});
const token = signInResponse.data.generateCustomerToken.token;
await (customerAccessTokenLifetime
? setToken(token, customerAccessTokenLifetime)
const customerTokenLifetime =
signInResponse.data.generateCustomerToken
.customer_token_lifetime;
await (customerTokenLifetime
? setToken(token, customerTokenLifetime)
: setToken(token));
// Clear all cart/customer data from cache and redux.
await apolloClient.clearCacheData(apolloClient, 'cart');
@@ -197,7 +181,6 @@ export const useCreateAccount = props => {
},

[
customerAccessTokenLifetime,
cartId,
generateReCaptchaData,
createAccount,
@@ -242,8 +225,7 @@ export const useCreateAccount = props => {
handleCancelKeyPress,
initialValues: sanitizedInitialValues,
isDisabled: isSubmitting || isGettingDetails || recaptchaLoading,
recaptchaWidgetProps,
minimumPasswordLength
recaptchaWidgetProps
};
};

@@ -257,7 +239,6 @@ export const useCreateAccount = props => {
*
* @property {GraphQLAST} customerQuery query to fetch customer details
* @property {GraphQLAST} getCartDetailsQuery query to get cart details
* @property {GraphQLAST} getStoreConfigQuery query to get store config
*/

/**

This file was deleted.

7,491 changes: 7,309 additions & 182 deletions packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/peregrine/lib/talons/SignIn/signIn.gql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { gql } from '@apollo/client';
import { CheckoutPageFragment } from '../CheckoutPage/checkoutPageFragments.gql';
import { GET_STORE_CONFIG_DATA } from '../CreateAccount/createAccount.gql';

export const GET_CUSTOMER = gql`
query GetCustomerAfterSignIn {
@@ -18,6 +17,7 @@ export const SIGN_IN = gql`
mutation SignIn($email: String!, $password: String!) {
generateCustomerToken(email: $email, password: $password) {
token
customer_token_lifetime
}
}
`;
@@ -52,6 +52,5 @@ export default {
createCartMutation: CREATE_CART,
getCustomerQuery: GET_CUSTOMER,
mergeCartsMutation: MERGE_CARTS,
signInMutation: SIGN_IN,
getStoreConfigQuery: GET_STORE_CONFIG_DATA
signInMutation: SIGN_IN
};
27 changes: 8 additions & 19 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useRef, useState, useMemo } from 'react';
import { useApolloClient, useMutation, useQuery } from '@apollo/client';
import { useApolloClient, useMutation } from '@apollo/client';

import { useGoogleReCaptcha } from '../../hooks/useGoogleReCaptcha/useGoogleReCaptcha';
import mergeOperations from '../../util/shallowMerge';
@@ -25,8 +25,7 @@ export const useSignIn = props => {
createCartMutation,
getCustomerQuery,
mergeCartsMutation,
signInMutation,
getStoreConfigQuery
signInMutation
} = operations;

const apolloClient = useApolloClient();
@@ -62,19 +61,6 @@ export const useSignIn = props => {
recaptchaWidgetProps
} = googleReCaptcha;

const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first'
});

const { customerAccessTokenLifetime } = useMemo(() => {
const storeConfig = storeConfigData?.storeConfig || {};

return {
customerAccessTokenLifetime:
storeConfig.customer_access_token_lifetime
};
}, [storeConfigData]);
const [fetchCartId] = useMutation(createCartMutation);
const [mergeCarts] = useMutation(mergeCartsMutation);
const fetchUserDetails = useAwaitQuery(getCustomerQuery);
@@ -105,8 +91,12 @@ export const useSignIn = props => {
});

const token = signInResponse.data.generateCustomerToken.token;
await (customerAccessTokenLifetime
? setToken(token, customerAccessTokenLifetime)
const customerTokenLifetime =
signInResponse.data.generateCustomerToken
.customer_token_lifetime;

await (customerTokenLifetime
? setToken(token, customerTokenLifetime)
: setToken(token));

// Clear all cart/customer data from cache and redux.
@@ -153,7 +143,6 @@ export const useSignIn = props => {
}
},
[
customerAccessTokenLifetime,
cartId,
generateReCaptchaData,
signIn,
Original file line number Diff line number Diff line change
@@ -65,8 +65,7 @@ const CreateAccount = props => {
handleSubmit,
isDisabled,
initialValues,
recaptchaWidgetProps,
minimumPasswordLength
recaptchaWidgetProps
} = talonProps;

return (
@@ -156,7 +155,7 @@ const CreateAccount = props => {
data-cy="OrderConfirmationPage-CreateAccount-password"
validate={combine([
isRequired,
[hasLengthAtLeast, minimumPasswordLength],
[hasLengthAtLeast, 8],
validatePassword
])}
validateOnBlur
Original file line number Diff line number Diff line change
@@ -14,11 +14,7 @@ jest.mock('@apollo/client', () => ({
}
]),
useQuery: jest.fn().mockImplementation(() => ({
data: {
storeConfig: {
minimum_password_length: 8 // or whatever value is expected
}
},
data: {},
loading: false,
error: null
}))
Original file line number Diff line number Diff line change
@@ -35,10 +35,8 @@ const CreateAccount = props => {
handleCancelKeyPress,
isDisabled,
initialValues,
recaptchaWidgetProps,
minimumPasswordLength
recaptchaWidgetProps
} = talonProps;
console.log('minimumPasswordLength==', minimumPasswordLength);
const { formatMessage } = useIntl();
const classes = useStyle(defaultClasses, props.classes);

@@ -166,7 +164,7 @@ const CreateAccount = props => {
})}
validate={combine([
isRequired,
[hasLengthAtLeast, minimumPasswordLength],
[hasLengthAtLeast, 8],
validatePassword
])}
validateOnBlur