-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(checkout): correctly switch package type based on shipping methods
- Loading branch information
1 parent
0334013
commit 7e91e95
Showing
33 changed files
with
217 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {type PdkFormData} from '../types'; | ||
import {AddressType} from '../data'; | ||
|
||
export const DEFAULT_MOCK_FORM_DATA = Object.freeze({ | ||
'address-type': AddressType.Billing, | ||
'b-address1': 'Straatnaam 12e', | ||
'b-address2': '', | ||
'b-city': 'Amsterdam', | ||
'b-country': 'NL', | ||
'b-postal-code': '1234AB', | ||
's-address1': 'Straatnaam 12e', | ||
's-address2': '', | ||
's-city': 'Amsterdam', | ||
's-country': 'NL', | ||
's-postal-code': '1234AB', | ||
'shipping-method': 'standard', | ||
} satisfies PdkFormData); |
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export * from './constants'; | ||
export * from './getMockCheckoutContext'; | ||
export * from './getMockFormData'; | ||
export * from './getMockPdkCheckoutConfig'; | ||
export * from './mockDeliveryOptionsElement'; | ||
export * from './mockPdkCheckout'; | ||
export * from './mockShippingMethod'; | ||
export * from './spies'; |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {getFormDataSpy} from './spies'; | ||
|
||
export const mockShippingMethod = (shippingMethod: string): void => { | ||
getFormDataSpy.mockReturnValue({ | ||
...getFormDataSpy(), | ||
'shipping-method': shippingMethod, | ||
}); | ||
}; |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {useConfig} from '../utils'; | ||
import {type PdkCheckoutConfig} from '../types'; | ||
|
||
export const defaultFormChange = ((callback) => { | ||
const config = useConfig(); | ||
const form = config.getForm(); | ||
|
||
form.addEventListener('change', callback); | ||
}) satisfies PdkCheckoutConfig['formChange']; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {type PdkCheckoutConfig} from '../types'; | ||
import {type AddressType} from '../data'; | ||
|
||
export const defaultGetAddressType = ((value) => value as AddressType) satisfies PdkCheckoutConfig['getAddressType']; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {useConfig} from '../utils'; | ||
import {type PdkCheckoutConfig} from '../types'; | ||
|
||
export const defaultGetFormData = (() => { | ||
const config = useConfig(); | ||
const form = config.getForm(); | ||
|
||
const formData = new FormData(form); | ||
|
||
return Object.fromEntries(formData.entries()); | ||
}) satisfies PdkCheckoutConfig['getFormData']; | ||
8 changes: 8 additions & 0 deletions
8
libs/checkout-common/src/defaults/defaultHasDeliveryOptions.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {getEnabledShippingMethods} from '../utils'; | ||
import {type PdkCheckoutConfig} from '../types'; | ||
|
||
export const defaultHasDeliveryOptions = ((shippingMethod: string): boolean => { | ||
const enabledShippingMethods = getEnabledShippingMethods(); | ||
|
||
return enabledShippingMethods.some((method) => shippingMethod === method); | ||
}) satisfies PdkCheckoutConfig['hasDeliveryOptions']; | ||
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './defaultFormChange'; | ||
export * from './defaultGetAddressType'; | ||
export * from './defaultGetFormData'; | ||
export * from './defaultHasDeliveryOptions'; |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {useSettings} from './useSettings'; | ||
|
||
export const getEnabledShippingMethods = (): string[] => { | ||
const settings = useSettings(); | ||
// No need to filter keys, 0 (off) is not included in the object | ||
const entries = Object.entries(settings.allowedShippingMethods); | ||
|
||
return entries.flatMap(([, value]) => value); | ||
}; | ||
This file contains 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 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
Oops, something went wrong.