-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix non-default package types not working
INT-447
- Loading branch information
1 parent
fe2c0a0
commit 2cb7d87
Showing
4 changed files
with
114 additions
and
17 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
apps/delivery-options/src/composables/useDeliveryMomentOptions.spec.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,98 @@ | ||
import {type ComputedRef} from 'vue'; | ||
import {describe, it, expect, beforeEach} from 'vitest'; | ||
import {setActivePinia, createPinia} from 'pinia'; | ||
import {flushPromises} from '@vue/test-utils'; | ||
import { | ||
KEY_CONFIG, | ||
ConfigSetting, | ||
CarrierSetting, | ||
KEY_CARRIER_SETTINGS, | ||
DELIVERY_TYPE_DEFAULT, | ||
PACKAGE_TYPE_DEFAULT, | ||
type SupportedPackageTypeName, | ||
type SelectOption, | ||
} from '@myparcel-do/shared'; | ||
import {CarrierName, PackageTypeName} from '@myparcel/constants'; | ||
import {parseJson} from '../utils'; | ||
import {type SelectedDeliveryMoment} from '../types'; | ||
import {mockSelectedDeliveryOptions, mockDeliveryOptionsConfig} from '../__tests__'; | ||
import {useDeliveryMomentOptions} from './useDeliveryMomentOptions'; | ||
|
||
const setup = async (packageType?: SupportedPackageTypeName): Promise<ComputedRef<SelectOption<string>[]>> => { | ||
mockDeliveryOptionsConfig({ | ||
[KEY_CONFIG]: { | ||
[ConfigSetting.ShowDeliveryDate]: true, | ||
[KEY_CARRIER_SETTINGS]: { | ||
[CarrierName.PostNl]: { | ||
[CarrierSetting.AllowDeliveryOptions]: true, | ||
[CarrierSetting.AllowStandardDelivery]: true, | ||
[CarrierSetting.AllowEveningDelivery]: true, | ||
[CarrierSetting.AllowMorningDelivery]: true, | ||
}, | ||
[CarrierName.DhlForYou]: { | ||
[CarrierSetting.AllowDeliveryOptions]: true, | ||
[CarrierSetting.AllowStandardDelivery]: true, | ||
[CarrierSetting.AllowEveningDelivery]: true, | ||
[CarrierSetting.AllowMorningDelivery]: true, | ||
}, | ||
}, | ||
// TODO: allow optional key to be passed with undefined as value | ||
...(packageType ? {[CarrierSetting.PackageType]: packageType} : {}), | ||
}, | ||
}); | ||
mockSelectedDeliveryOptions(); | ||
|
||
const options = useDeliveryMomentOptions(); | ||
await flushPromises(); | ||
|
||
return options; | ||
}; | ||
|
||
describe('useDeliveryMomentOptions', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
|
||
it('returns delivery moment options', async () => { | ||
expect.assertions(8); | ||
const options = await setup(); | ||
|
||
expect(options.value).toHaveLength(1); | ||
|
||
options.value.forEach((option) => { | ||
expect(Object.keys(option)).toEqual(['carrier', 'label', 'price', 'value']); | ||
expect(option.value).toBeTypeOf('string'); | ||
|
||
const parsedValue = parseJson<SelectedDeliveryMoment>(option.value); | ||
|
||
expect(parsedValue.carrier).toBe(CarrierName.PostNl); | ||
expect(parsedValue.time).not.toBeNull(); | ||
expect(parsedValue.deliveryType).toBe(DELIVERY_TYPE_DEFAULT); | ||
expect(parsedValue.packageType).toBe(PACKAGE_TYPE_DEFAULT); | ||
expect(parsedValue.shipmentOptions).toEqual([]); | ||
}); | ||
}); | ||
|
||
it.each([PackageTypeName.Mailbox, PackageTypeName.DigitalStamp, PackageTypeName.PackageSmall])( | ||
'returns delivery moment options for different package types', | ||
async (packageType) => { | ||
expect.assertions(8); | ||
const options = await setup(packageType); | ||
|
||
expect(options.value).toHaveLength(1); | ||
|
||
options.value.forEach((option) => { | ||
expect(Object.keys(option)).toEqual(['carrier', 'label', 'price', 'value']); | ||
expect(option.value).toBeTypeOf('string'); | ||
|
||
const parsedValue = parseJson<SelectedDeliveryMoment>(option.value); | ||
|
||
expect(parsedValue.carrier).toBe(CarrierName.PostNl); | ||
expect(parsedValue.time).toBeNull(); | ||
expect(parsedValue.deliveryType).toBe(DELIVERY_TYPE_DEFAULT); | ||
expect(parsedValue.packageType).toBe(packageType); | ||
expect(parsedValue.shipmentOptions).toEqual([]); | ||
}); | ||
}, | ||
); | ||
}); |
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