diff --git a/apps/delivery-options/src/composables/__snapshots__/useDeliveryMomentOptions.spec.ts.snap b/apps/delivery-options/src/composables/__snapshots__/useDeliveryMomentOptions.spec.ts.snap new file mode 100644 index 00000000..3b3ad751 --- /dev/null +++ b/apps/delivery-options/src/composables/__snapshots__/useDeliveryMomentOptions.spec.ts.snap @@ -0,0 +1,143 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`useDeliveryMomentOptions > returns delivery moment options with package type digital_stamp 1`] = ` +[ + { + "carrier": "postnl", + "label": { + "key": "packageTypeDigitalStamp", + }, + "price": 0, + "value": { + "carrier": "postnl", + "date": null, + "deliveryType": "standard", + "packageType": "digital_stamp", + "shipmentOptions": [], + "time": null, + }, + }, + { + "carrier": "postnl:123", + "label": { + "key": "packageTypeDigitalStamp", + }, + "price": 4, + "value": { + "carrier": "postnl:123", + "date": null, + "deliveryType": "standard", + "packageType": "digital_stamp", + "shipmentOptions": [], + "time": null, + }, + }, +] +`; + +exports[`useDeliveryMomentOptions > returns delivery moment options with package type mailbox 1`] = ` +[ + { + "carrier": "postnl", + "label": { + "key": "packageTypeMailbox", + }, + "price": 0, + "value": { + "carrier": "postnl", + "date": null, + "deliveryType": "standard", + "packageType": "mailbox", + "shipmentOptions": [], + "time": null, + }, + }, + { + "carrier": "postnl:123", + "label": { + "key": "packageTypeMailbox", + }, + "price": 5, + "value": { + "carrier": "postnl:123", + "date": null, + "deliveryType": "standard", + "packageType": "mailbox", + "shipmentOptions": [], + "time": null, + }, + }, +] +`; + +exports[`useDeliveryMomentOptions > returns delivery moment options with package type package 1`] = ` +[ + { + "carrier": "postnl", + "label": { + "key": "deliveryStandardTitle", + }, + "price": 3, + "value": { + "carrier": "postnl", + "deliveryType": "standard", + "packageType": "package", + "shipmentOptions": [], + "time": { + "key": "deliveryStandardTitle", + }, + }, + }, + { + "carrier": "postnl:123", + "label": { + "key": "deliveryStandardTitle", + }, + "price": 456, + "value": { + "carrier": "postnl:123", + "deliveryType": "standard", + "packageType": "package", + "shipmentOptions": [], + "time": { + "key": "deliveryStandardTitle", + }, + }, + }, +] +`; + +exports[`useDeliveryMomentOptions > returns delivery moment options with package type package_small 1`] = ` +[ + { + "carrier": "postnl", + "label": { + "key": "packageTypePackageSmall", + }, + "price": 6, + "value": { + "carrier": "postnl", + "date": null, + "deliveryType": "standard", + "packageType": "package_small", + "shipmentOptions": [], + "time": null, + }, + }, + { + "carrier": "postnl:123", + "label": { + "key": "packageTypePackageSmall", + }, + "price": 0, + "value": { + "carrier": "postnl:123", + "date": null, + "deliveryType": "standard", + "packageType": "package_small", + "shipmentOptions": [], + "time": null, + }, + }, +] +`; diff --git a/apps/delivery-options/src/composables/useDeliveryMomentOptions.spec.ts b/apps/delivery-options/src/composables/useDeliveryMomentOptions.spec.ts index cdf5dfc8..983a86cb 100644 --- a/apps/delivery-options/src/composables/useDeliveryMomentOptions.spec.ts +++ b/apps/delivery-options/src/composables/useDeliveryMomentOptions.spec.ts @@ -3,14 +3,12 @@ import {describe, it, expect, beforeEach} from 'vitest'; import {setActivePinia, createPinia} from 'pinia'; import {flushPromises} from '@vue/test-utils'; import { + type SupportedPackageTypeName, + type SelectOption, KEY_CONFIG, - ConfigSetting, CarrierSetting, + ConfigSetting, 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'; @@ -28,8 +26,16 @@ const setup = async (packageType?: SupportedPackageTypeName): Promise { setActivePinia(createPinia()); }); - it('returns delivery moment options', async () => { - expect.assertions(8); - const options = await setup(); + it.each([ + PackageTypeName.Package, + PackageTypeName.Mailbox, + PackageTypeName.DigitalStamp, + PackageTypeName.PackageSmall, + ])('returns delivery moment options with package type %s', async (packageType) => { + expect.assertions(2); - expect(options.value).toHaveLength(1); + const options = await setup(packageType); - options.value.forEach((option) => { - expect(Object.keys(option)).toEqual(['carrier', 'label', 'price', 'value']); - expect(option.value).toBeTypeOf('string'); + expect(options.value).toHaveLength(2); - const parsedValue = parseJson(option.value); + const resolved = options.value.map((option) => ({ + ...option, + value: parseJson(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([]); - }); + expect(resolved).toMatchSnapshot(); }); - - 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(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([]); - }); - }, - ); }); diff --git a/apps/delivery-options/src/composables/useDeliveryMomentOptions.ts b/apps/delivery-options/src/composables/useDeliveryMomentOptions.ts index 875b57e9..6d19334c 100644 --- a/apps/delivery-options/src/composables/useDeliveryMomentOptions.ts +++ b/apps/delivery-options/src/composables/useDeliveryMomentOptions.ts @@ -16,14 +16,14 @@ export const useDeliveryMomentOptions = (): ComputedRef[]> return activeCarriers.value .filter((carrier) => toValue(carrier.hasAnyDelivery) && toValue(carrier.packageTypes).has(config.packageType)) .map((carrier) => { - const resolvedCarrier = toValue(carrier.carrier); + const carrierIdentifier = toValue(carrier.carrier).identifier; return { - carrier: resolvedCarrier.name, + carrier: carrierIdentifier, label: createPackageTypeTranslatable(config.packageType), - price: getDeliveryTypePrice(DELIVERY_TYPE_DEFAULT, resolvedCarrier.name), + price: getDeliveryTypePrice(DELIVERY_TYPE_DEFAULT, carrierIdentifier), value: JSON.stringify({ - carrier: resolvedCarrier.name, + carrier: carrierIdentifier, date: null, deliveryType: DELIVERY_TYPE_DEFAULT, packageType: config.packageType,