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

PWA-1564: [bug]: Guest checkout, France region validation failed #3133

Merged
merged 5 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Object {
"lastName": "ba ln",
"phoneNumber": "1234567891",
"postcode": "78945",
"region": "TX",
"region": 5,
"street1": "45678 blvd",
"street2": "suite 300",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const billingAddress = {
},
street: ['45678 blvd', 'suite 300'],
city: 'Austin',
region: { code: 'TX' },
region: { code: 'TX', region_id: 5 },
postcode: '78945',
phoneNumber: '1234567891'
};
Expand Down Expand Up @@ -446,7 +446,9 @@ describe('Testing payment nonce request workflow', () => {
street1: 'test value',
street2: 'test value',
city: 'test value',
region: 'test value',
region: {
region_id: 20
},
postcode: 'test value',
phoneNumber: 'test value'
};
Expand Down Expand Up @@ -479,7 +481,8 @@ describe('Testing payment nonce request workflow', () => {
variables: {
...billingAddress,
sameAsShipping: false,
cartId: '123'
cartId: '123',
region: 20
}
});
});
Expand Down Expand Up @@ -763,12 +766,31 @@ describe('Testing stepNumber', () => {
});

test('Should set stepNumber to 1 if shouldSubmit is set to true', () => {
const testFormState = {
values: {
firstName: 'Unit',
lastName: 'Test',
country: '',
street1: '',
street2: '',
city: '',
region: { region_id: 7 },
postcode: '12345',
phoneNumber: '1234567890'
},
errors: {}
};
useFormState
.mockReturnValueOnce(testFormState)
.mockReturnValueOnce(testFormState);

const { talonProps } = getTalonProps({
shouldSubmit: true,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
onError: () => {},
resetShouldSubmit: () => {}
});

expect(talonProps.stepNumber).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const GET_BILLING_ADDRESS = gql`
city
region {
code
label
region_id
}
postcode
phoneNumber: telephone
Expand All @@ -63,6 +65,7 @@ export const GET_SHIPPING_ADDRESS = gql`
city
region {
code
region_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need label for this one?

}
postcode
phoneNumber: telephone
Expand Down Expand Up @@ -114,6 +117,8 @@ export const SET_BILLING_ADDRESS = gql`
city
region {
code
label
region_id
}
postcode
telephone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const mapAddressData = rawAddressData => {
street1: street[0],
street2: street[1],
country: country.code,
region: region.code
region: region.region_id
};
} else {
return {};
Expand Down Expand Up @@ -256,7 +256,7 @@ export const useCreditCard = props => {
street1,
street2,
city,
region,
region: region.region_id,
postcode,
phoneNumber,
sameAsShipping: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ exports[`Should return correct shape 1`] = `
"root": "region",
}
}
fieldInput="region[label]"
fieldSelect="region[region_id]"
initialValue="sample region"
optionValueKey="id"
validate={[Function]}
/>
<mock-Postcode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ const CreditCard = props => {
classes={fieldClasses.region}
initialValue={initialValues.region}
validate={isFieldRequired}
fieldInput={'region[label]'}
fieldSelect={'region[region_id]'}
optionValueKey={'id'}
/>
<Postcode
classes={fieldClasses.postal_code}
Expand Down
4 changes: 2 additions & 2 deletions packages/venia-ui/lib/components/Region/region.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useIntl } from 'react-intl';
import { func, shape, string } from 'prop-types';
import { func, number, oneOfType, shape, string } from 'prop-types';
import { useRegion } from '@magento/peregrine/lib/talons/Region/useRegion';

import { mergeClasses } from '../../classify';
Expand Down Expand Up @@ -89,5 +89,5 @@ Region.propTypes = {
translationId: string,
optionValueKey: string,
validate: func,
initialValue: string
initialValue: oneOfType([number, string])
};