@@ -2015,4 +2015,176 @@ describe('Checkout One Click', () => {
20152015 expect ( calls [ 2 ] [ 0 ] . body . address1 ) . toBe ( '789 Pine Rd' )
20162016 expect ( calls [ 2 ] [ 0 ] . body . city ) . toBe ( 'Miami' )
20172017 } )
2018+
2019+ test ( 'saves contactPhone from contact info form instead of shipping address phone for multi-shipment orders' , async ( ) => {
2020+ // Clear previous mock calls
2021+ mockUseShopperCustomersMutation . mockClear ( )
2022+ mockUseShopperCustomersMutation . mockResolvedValue ( { } )
2023+
2024+ // Set up a multi-shipment order with phone numbers in shipping addresses
2025+ const multiShipmentOrder = {
2026+ customerInfo : { customerId : 'new-customer-id' } ,
2027+ shipments : [
2028+ {
2029+ shipmentId : 'me' ,
2030+ shippingMethod : {
2031+ id : '001' ,
2032+ c_storePickupEnabled : false
2033+ } ,
2034+ shippingAddress : {
2035+ address1 : '123 Main St' ,
2036+ city : 'Tampa' ,
2037+ countryCode : 'US' ,
2038+ firstName : 'Test' ,
2039+ lastName : 'User' ,
2040+ phone : '(727) 555-1234' , // Different phone in shipping address
2041+ postalCode : '33712' ,
2042+ stateCode : 'FL'
2043+ }
2044+ } ,
2045+ {
2046+ shipmentId : 'shipment2' ,
2047+ shippingMethod : {
2048+ id : '002' ,
2049+ c_storePickupEnabled : false
2050+ } ,
2051+ shippingAddress : {
2052+ address1 : '456 Oak Ave' ,
2053+ city : 'Orlando' ,
2054+ countryCode : 'US' ,
2055+ firstName : 'Test' ,
2056+ lastName : 'User' ,
2057+ phone : '(407) 555-5678' , // Different phone in shipping address
2058+ postalCode : '32801' ,
2059+ stateCode : 'FL'
2060+ }
2061+ }
2062+ ] ,
2063+ billingAddress : { }
2064+ }
2065+
2066+ const currentCustomer = { isRegistered : true }
2067+ const registeredUserChoseGuest = false
2068+ const enableUserRegistration = true
2069+ // Contact phone from contact info form (should take priority)
2070+ const contactPhone = '(555) 123-4567'
2071+
2072+ // Simulate the phone saving logic from index.jsx
2073+ const customerId = multiShipmentOrder . customerInfo ?. customerId
2074+ if ( customerId ) {
2075+ const { isPickupShipment} = await import (
2076+ '@salesforce/retail-react-app/app/utils/shipment-utils'
2077+ )
2078+ const deliveryShipments =
2079+ multiShipmentOrder ?. shipments ?. filter (
2080+ ( shipment ) => ! isPickupShipment ( shipment ) && shipment . shippingAddress
2081+ ) || [ ]
2082+
2083+ if (
2084+ enableUserRegistration &&
2085+ currentCustomer ?. isRegistered &&
2086+ ! registeredUserChoseGuest
2087+ ) {
2088+ // Save addresses first (not testing this part)
2089+ // ... address saving logic ...
2090+
2091+ // Test phone saving logic - contactPhone should take priority
2092+ const phoneHome =
2093+ contactPhone && contactPhone . length > 0
2094+ ? contactPhone
2095+ : deliveryShipments . length > 0
2096+ ? deliveryShipments [ 0 ] ?. shippingAddress ?. phone
2097+ : null
2098+
2099+ if ( phoneHome ) {
2100+ mockUseShopperCustomersMutation ( {
2101+ parameters : { customerId} ,
2102+ body : { phoneHome}
2103+ } )
2104+ }
2105+ }
2106+ }
2107+
2108+ // Verify updateCustomer was called with contactPhone, not shipping address phone
2109+ expect ( mockUseShopperCustomersMutation ) . toHaveBeenCalledTimes ( 1 )
2110+ const call = mockUseShopperCustomersMutation . mock . calls [ 0 ]
2111+ expect ( call [ 0 ] . body . phoneHome ) . toBe ( '(555) 123-4567' ) // Should be contactPhone, not shipping address phone
2112+ expect ( call [ 0 ] . body . phoneHome ) . not . toBe ( '(727) 555-1234' ) // Should not be first shipping address phone
2113+ expect ( call [ 0 ] . body . phoneHome ) . not . toBe ( '(407) 555-5678' ) // Should not be second shipping address phone
2114+ } )
2115+
2116+ test ( 'falls back to shipping address phone when contactPhone is empty for multi-shipment orders' , async ( ) => {
2117+ // Clear previous mock calls
2118+ mockUseShopperCustomersMutation . mockClear ( )
2119+ mockUseShopperCustomersMutation . mockResolvedValue ( { } )
2120+
2121+ // Set up a multi-shipment order with phone numbers in shipping addresses
2122+ const multiShipmentOrder = {
2123+ customerInfo : { customerId : 'new-customer-id' } ,
2124+ shipments : [
2125+ {
2126+ shipmentId : 'me' ,
2127+ shippingMethod : {
2128+ id : '001' ,
2129+ c_storePickupEnabled : false
2130+ } ,
2131+ shippingAddress : {
2132+ address1 : '123 Main St' ,
2133+ city : 'Tampa' ,
2134+ countryCode : 'US' ,
2135+ firstName : 'Test' ,
2136+ lastName : 'User' ,
2137+ phone : '(727) 555-1234' , // This should be used as fallback
2138+ postalCode : '33712' ,
2139+ stateCode : 'FL'
2140+ }
2141+ }
2142+ ] ,
2143+ billingAddress : { }
2144+ }
2145+
2146+ const currentCustomer = { isRegistered : true }
2147+ const registeredUserChoseGuest = false
2148+ const enableUserRegistration = true
2149+ // Contact phone is empty (should fall back to shipping address phone)
2150+ const contactPhone = ''
2151+
2152+ // Simulate the phone saving logic from index.jsx
2153+ const customerId = multiShipmentOrder . customerInfo ?. customerId
2154+ if ( customerId ) {
2155+ const { isPickupShipment} = await import (
2156+ '@salesforce/retail-react-app/app/utils/shipment-utils'
2157+ )
2158+ const deliveryShipments =
2159+ multiShipmentOrder ?. shipments ?. filter (
2160+ ( shipment ) => ! isPickupShipment ( shipment ) && shipment . shippingAddress
2161+ ) || [ ]
2162+
2163+ if (
2164+ enableUserRegistration &&
2165+ currentCustomer ?. isRegistered &&
2166+ ! registeredUserChoseGuest
2167+ ) {
2168+ // Test phone saving logic - should fall back to shipping address phone
2169+ const phoneHome =
2170+ contactPhone && contactPhone . length > 0
2171+ ? contactPhone
2172+ : deliveryShipments . length > 0
2173+ ? deliveryShipments [ 0 ] ?. shippingAddress ?. phone
2174+ : null
2175+
2176+ if ( phoneHome ) {
2177+ mockUseShopperCustomersMutation ( {
2178+ parameters : { customerId} ,
2179+ body : { phoneHome}
2180+ } )
2181+ }
2182+ }
2183+ }
2184+
2185+ // Verify updateCustomer was called with shipping address phone as fallback
2186+ expect ( mockUseShopperCustomersMutation ) . toHaveBeenCalledTimes ( 1 )
2187+ const call = mockUseShopperCustomersMutation . mock . calls [ 0 ]
2188+ expect ( call [ 0 ] . body . phoneHome ) . toBe ( '(727) 555-1234' ) // Should be shipping address phone
2189+ } )
20182190} )
0 commit comments