-
Notifications
You must be signed in to change notification settings - Fork 212
@W-20892577 Save phone number during user registration of BOPIS orders #3577
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
Closed
syadupathi-sf
wants to merge
1
commit into
feature/1cc_merge
from
syadupathi.W-20892577.savePhNumBopis
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1717,4 +1717,255 @@ describe('Checkout One Click', () => { | |
| expect(calls[2][0].body.address1).toBe('789 Pine Rd') | ||
| expect(calls[2][0].body.city).toBe('Miami') | ||
| }) | ||
|
|
||
| test('saves phone number to customer profile for pickup-only orders during user registration', async () => { | ||
| // Reset mock | ||
| mockUseShopperCustomersMutation.mockClear() | ||
|
|
||
| // Create a pickup-only order (no delivery shipments) | ||
| const pickupOnlyOrder = { | ||
| orderNo: '00000101', | ||
| customerInfo: { | ||
| customerId: 'new-customer-id', | ||
| customerNo: 'guest123', | ||
| email: '[email protected]' | ||
| }, | ||
| shipments: [ | ||
| { | ||
| shipmentId: 'pickup1', | ||
| c_fromStoreId: 'store1', | ||
| shippingMethod: {id: 'PICKUP', c_storePickupEnabled: true}, | ||
| shippingAddress: { | ||
| firstName: 'Store 1', | ||
| lastName: 'Pickup', | ||
| address1: '1 Market St', | ||
| city: 'San Francisco', | ||
| postalCode: '94105', | ||
| stateCode: 'CA', | ||
| countryCode: 'US' | ||
| } | ||
| } | ||
| ], | ||
| billingAddress: { | ||
| firstName: 'John', | ||
| lastName: 'Doe', | ||
| phone: '(555) 123-4567' | ||
| } | ||
| } | ||
|
|
||
| const currentCustomer = {isRegistered: true} | ||
| const registeredUserChoseGuest = false | ||
| const enableUserRegistration = true | ||
| const contactPhone = '(555) 987-6543' // Phone from contact info form | ||
|
|
||
| // Simulate the phone saving logic from index.jsx | ||
| const customerId = pickupOnlyOrder.customerInfo?.customerId | ||
| if (customerId) { | ||
| const {isPickupShipment} = await import( | ||
| '@salesforce/retail-react-app/app/utils/shipment-utils' | ||
| ) | ||
| const deliveryShipments = | ||
| pickupOnlyOrder?.shipments?.filter( | ||
| (shipment) => !isPickupShipment(shipment) && shipment.shippingAddress | ||
| ) || [] | ||
|
|
||
| if ( | ||
| enableUserRegistration && | ||
| currentCustomer?.isRegistered && | ||
| !registeredUserChoseGuest | ||
| ) { | ||
| // For pickup-only orders, deliveryShipments.length will be 0 | ||
| // but phone number should still be saved | ||
| if (deliveryShipments.length > 0) { | ||
| // This block won't execute for pickup-only orders | ||
| // but we're testing that phone is saved regardless | ||
| } | ||
|
|
||
| // Persist phone number as phoneHome for all order types (delivery and pickup) | ||
| // Try billing address phone first, then fall back to contact phone from context | ||
| const phoneHome = | ||
| pickupOnlyOrder?.billingAddress?.phone || | ||
| contactPhone || | ||
| null | ||
| if (phoneHome) { | ||
| await mockUseShopperCustomersMutation({ | ||
| parameters: {customerId}, | ||
| body: {phoneHome} | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Verify updateCustomer was called with phoneHome | ||
| expect(mockUseShopperCustomersMutation).toHaveBeenCalledTimes(1) | ||
| expect(mockUseShopperCustomersMutation).toHaveBeenCalledWith({ | ||
| parameters: {customerId: 'new-customer-id'}, | ||
| body: {phoneHome: '(555) 123-4567'} // Should use billing address phone first | ||
| }) | ||
| }) | ||
|
|
||
| test('saves phone number from contact info when billing address phone is missing for pickup orders', async () => { | ||
| // Reset mock | ||
| mockUseShopperCustomersMutation.mockClear() | ||
|
|
||
| // Create a pickup-only order without billing address phone | ||
| const pickupOnlyOrder = { | ||
| orderNo: '00000101', | ||
| customerInfo: { | ||
| customerId: 'new-customer-id', | ||
| customerNo: 'guest123', | ||
| email: '[email protected]' | ||
| }, | ||
| shipments: [ | ||
| { | ||
| shipmentId: 'pickup1', | ||
| c_fromStoreId: 'store1', | ||
| shippingMethod: {id: 'PICKUP', c_storePickupEnabled: true}, | ||
| shippingAddress: { | ||
| firstName: 'Store 1', | ||
| lastName: 'Pickup', | ||
| address1: '1 Market St', | ||
| city: 'San Francisco', | ||
| postalCode: '94105', | ||
| stateCode: 'CA', | ||
| countryCode: 'US' | ||
| } | ||
| } | ||
| ], | ||
| billingAddress: { | ||
| firstName: 'John', | ||
| lastName: 'Doe' | ||
| // No phone in billing address | ||
| } | ||
| } | ||
|
|
||
| const currentCustomer = {isRegistered: true} | ||
| const registeredUserChoseGuest = false | ||
| const enableUserRegistration = true | ||
| const contactPhone = '(555) 987-6543' // Phone from contact info form | ||
|
|
||
| // Simulate the phone saving logic from index.jsx | ||
| const customerId = pickupOnlyOrder.customerInfo?.customerId | ||
| if (customerId) { | ||
| const {isPickupShipment} = await import( | ||
| '@salesforce/retail-react-app/app/utils/shipment-utils' | ||
| ) | ||
| const deliveryShipments = | ||
| pickupOnlyOrder?.shipments?.filter( | ||
| (shipment) => !isPickupShipment(shipment) && shipment.shippingAddress | ||
| ) || [] | ||
|
|
||
| if ( | ||
| enableUserRegistration && | ||
| currentCustomer?.isRegistered && | ||
| !registeredUserChoseGuest | ||
| ) { | ||
| // Persist phone number as phoneHome for all order types (delivery and pickup) | ||
| // Try billing address phone first, then fall back to contact phone from context | ||
| const phoneHome = | ||
| pickupOnlyOrder?.billingAddress?.phone || | ||
| contactPhone || | ||
| null | ||
| if (phoneHome) { | ||
| await mockUseShopperCustomersMutation({ | ||
| parameters: {customerId}, | ||
| body: {phoneHome} | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Verify updateCustomer was called with phoneHome from contact info | ||
| expect(mockUseShopperCustomersMutation).toHaveBeenCalledTimes(1) | ||
| expect(mockUseShopperCustomersMutation).toHaveBeenCalledWith({ | ||
| parameters: {customerId: 'new-customer-id'}, | ||
| body: {phoneHome: '(555) 987-6543'} // Should fall back to contact phone | ||
| }) | ||
| }) | ||
|
|
||
| test('saves phone number to customer profile for delivery orders during user registration', async () => { | ||
| // Reset mock | ||
| mockUseShopperCustomersMutation.mockClear() | ||
|
|
||
| // Create a delivery order | ||
| const deliveryOrder = { | ||
| orderNo: '00000101', | ||
| customerInfo: { | ||
| customerId: 'new-customer-id', | ||
| customerNo: 'guest123', | ||
| email: '[email protected]' | ||
| }, | ||
| shipments: [ | ||
| { | ||
| shipmentId: 'shipment1', | ||
| shippingMethod: { | ||
| id: '002', | ||
| c_storePickupEnabled: false | ||
| }, | ||
| shippingAddress: { | ||
| address1: '123 Main St', | ||
| city: 'Tampa', | ||
| countryCode: 'US', | ||
| firstName: 'Test', | ||
| lastName: 'User', | ||
| phone: '(727) 555-1234', | ||
| postalCode: '33712', | ||
| stateCode: 'FL' | ||
| } | ||
| } | ||
| ], | ||
| billingAddress: { | ||
| firstName: 'John', | ||
| lastName: 'Smith', | ||
| phone: '(555) 999-8888' | ||
| } | ||
| } | ||
|
|
||
| const currentCustomer = {isRegistered: true} | ||
| const registeredUserChoseGuest = false | ||
| const enableUserRegistration = true | ||
| const contactPhone = '(555) 777-6666' | ||
|
|
||
| // Simulate the phone saving logic from index.jsx | ||
| const customerId = deliveryOrder.customerInfo?.customerId | ||
| if (customerId) { | ||
| const {isPickupShipment} = await import( | ||
| '@salesforce/retail-react-app/app/utils/shipment-utils' | ||
| ) | ||
| const deliveryShipments = | ||
| deliveryOrder?.shipments?.filter( | ||
| (shipment) => !isPickupShipment(shipment) && shipment.shippingAddress | ||
| ) || [] | ||
|
|
||
| if ( | ||
| enableUserRegistration && | ||
| currentCustomer?.isRegistered && | ||
| !registeredUserChoseGuest | ||
| ) { | ||
| // Save delivery addresses (this would happen in real code) | ||
| if (deliveryShipments.length > 0) { | ||
| // Address saving would happen here, but we're just testing phone | ||
| } | ||
|
|
||
| // Persist phone number as phoneHome for all order types (delivery and pickup) | ||
| const phoneHome = | ||
| deliveryOrder?.billingAddress?.phone || | ||
| contactPhone || | ||
| null | ||
| if (phoneHome) { | ||
| await mockUseShopperCustomersMutation({ | ||
| parameters: {customerId}, | ||
| body: {phoneHome} | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Verify updateCustomer was called with phoneHome | ||
| expect(mockUseShopperCustomersMutation).toHaveBeenCalledTimes(1) | ||
| expect(mockUseShopperCustomersMutation).toHaveBeenCalledWith({ | ||
| parameters: {customerId: 'new-customer-id'}, | ||
| body: {phoneHome: '(555) 999-8888'} // Should use billing address phone | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting - we actually trying to extract phone number from the billing address?? So that means the field is required (?) I'd assume we should rely on the one filled out at the Contact Info stage..
Also wondering why this does not work for BOPIS (even though there is a phone number field on billing address form for BOPIS orders)