Skip to content
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

feat: allow UPS standard delivery in NL & BE, add UPS express delivery #262

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/delivery-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"dependencies": {
"@myparcel-do/shared": "workspace:*",
"@myparcel/constants": "^2.0.0",
"@myparcel/constants": "^2.2.0",
"@myparcel/sdk": "^4.0.0",
"@myparcel/ts-utils": "^1.12.0",
"@myparcel/vue-form-builder": "^1.0.0-beta.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/delivery-options/src/__tests__/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum TestValue {
DeliveryTypeSaturday = 1 << 6,
DeliveryTypeSameDay = 1 << 7,
DeliveryTypePickup = 1 << 8,
DeliveryTypeExpress = 1 << 9,

// Carriers
CarrierPostNl = 1 << 20,
Expand Down Expand Up @@ -76,4 +77,5 @@ export const TEST_VALUE_MAP_PRICES = Object.freeze({
[CarrierSetting.PriceSaturdayDelivery]: TestValue.DeliveryTypeSaturday,
[CarrierSetting.PriceSignature]: TestValue.ShipmentOptionSignature,
[CarrierSetting.PriceStandardDelivery]: TestValue.Default,
[CarrierSetting.PriceExpressDelivery]: TestValue.DeliveryTypeExpress,
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
"config": {
"allowDeliveryOptions": true,
"allowEveningDelivery": true,
"allowExpressDelivery": true,
"allowMondayDelivery": true,
"allowMorningDelivery": true,
"allowOnlyRecipient": true,
Expand All @@ -22,6 +23,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
"carrierSettings": {
"bpost": {
"priceEveningDelivery": 2097168,
"priceExpressDelivery": 2097664,
"priceMondayDelivery": 2097184,
"priceMorningDelivery": 2097160,
"priceOnlyRecipient": 2097664,
Expand All @@ -36,6 +38,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"bpost:1": {
"priceEveningDelivery": 2359312,
"priceExpressDelivery": 2359808,
"priceMondayDelivery": 2359328,
"priceMorningDelivery": 2359304,
"priceOnlyRecipient": 2359808,
Expand All @@ -50,6 +53,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"bpost:2": {
"priceEveningDelivery": 2621456,
"priceExpressDelivery": 2621952,
"priceMondayDelivery": 2621472,
"priceMorningDelivery": 2621448,
"priceOnlyRecipient": 2621952,
Expand All @@ -64,6 +68,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhl": {
"priceEveningDelivery": 33554448,
"priceExpressDelivery": 33554944,
"priceMondayDelivery": 33554464,
"priceMorningDelivery": 33554440,
"priceOnlyRecipient": 33554944,
Expand All @@ -78,6 +83,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhl:1": {
"priceEveningDelivery": 33816592,
"priceExpressDelivery": 33817088,
"priceMondayDelivery": 33816608,
"priceMorningDelivery": 33816584,
"priceOnlyRecipient": 33817088,
Expand All @@ -92,6 +98,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhl:2": {
"priceEveningDelivery": 34078736,
"priceExpressDelivery": 34079232,
"priceMondayDelivery": 34078752,
"priceMorningDelivery": 34078728,
"priceOnlyRecipient": 34079232,
Expand All @@ -106,6 +113,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhleuroplus": {
"priceEveningDelivery": 1073741840,
"priceExpressDelivery": 1073742336,
"priceMondayDelivery": 1073741856,
"priceMorningDelivery": 1073741832,
"priceOnlyRecipient": 1073742336,
Expand All @@ -120,6 +128,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhleuroplus:1": {
"priceEveningDelivery": 1074003984,
"priceExpressDelivery": 1074004480,
"priceMondayDelivery": 1074004000,
"priceMorningDelivery": 1074003976,
"priceOnlyRecipient": 1074004480,
Expand All @@ -134,6 +143,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhleuroplus:2": {
"priceEveningDelivery": 1074266128,
"priceExpressDelivery": 1074266624,
"priceMondayDelivery": 1074266144,
"priceMorningDelivery": 1074266120,
"priceOnlyRecipient": 1074266624,
Expand All @@ -148,6 +158,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhlforyou": {
"priceEveningDelivery": 268435472,
"priceExpressDelivery": 268435968,
"priceMondayDelivery": 268435488,
"priceMorningDelivery": 268435464,
"priceOnlyRecipient": 268435968,
Expand All @@ -162,6 +173,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhlforyou:1": {
"priceEveningDelivery": 268697616,
"priceExpressDelivery": 268698112,
"priceMondayDelivery": 268697632,
"priceMorningDelivery": 268697608,
"priceOnlyRecipient": 268698112,
Expand All @@ -176,6 +188,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhlforyou:2": {
"priceEveningDelivery": 268959760,
"priceExpressDelivery": 268960256,
"priceMondayDelivery": 268959776,
"priceMorningDelivery": 268959752,
"priceOnlyRecipient": 268960256,
Expand All @@ -190,6 +203,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhlparcelconnect": {
"priceEveningDelivery": 536870928,
"priceExpressDelivery": 536871424,
"priceMondayDelivery": 536870944,
"priceMorningDelivery": 536870920,
"priceOnlyRecipient": 536871424,
Expand All @@ -204,6 +218,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhlparcelconnect:1": {
"priceEveningDelivery": 537133072,
"priceExpressDelivery": 537133568,
"priceMondayDelivery": 537133088,
"priceMorningDelivery": 537133064,
"priceOnlyRecipient": 537133568,
Expand All @@ -218,6 +233,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dhlparcelconnect:2": {
"priceEveningDelivery": 537395216,
"priceExpressDelivery": 537395712,
"priceMondayDelivery": 537395232,
"priceMorningDelivery": 537395208,
"priceOnlyRecipient": 537395712,
Expand All @@ -232,6 +248,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dpd": {
"priceEveningDelivery": 8388624,
"priceExpressDelivery": 8389120,
"priceMondayDelivery": 8388640,
"priceMorningDelivery": 8388616,
"priceOnlyRecipient": 8389120,
Expand All @@ -246,6 +263,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dpd:1": {
"priceEveningDelivery": 8650768,
"priceExpressDelivery": 8651264,
"priceMondayDelivery": 8650784,
"priceMorningDelivery": 8650760,
"priceOnlyRecipient": 8651264,
Expand All @@ -260,6 +278,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"dpd:2": {
"priceEveningDelivery": 8912912,
"priceExpressDelivery": 8913408,
"priceMondayDelivery": 8912928,
"priceMorningDelivery": 8912904,
"priceOnlyRecipient": 8913408,
Expand All @@ -274,6 +293,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"postnl": {
"priceEveningDelivery": 1048592,
"priceExpressDelivery": 1049088,
"priceMondayDelivery": 1048608,
"priceMorningDelivery": 1048584,
"priceOnlyRecipient": 1049088,
Expand All @@ -288,6 +308,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"postnl:1": {
"priceEveningDelivery": 1310736,
"priceExpressDelivery": 1311232,
"priceMondayDelivery": 1310752,
"priceMorningDelivery": 1310728,
"priceOnlyRecipient": 1311232,
Expand All @@ -302,6 +323,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"postnl:2": {
"priceEveningDelivery": 1572880,
"priceExpressDelivery": 1573376,
"priceMondayDelivery": 1572896,
"priceMorningDelivery": 1572872,
"priceOnlyRecipient": 1573376,
Expand All @@ -316,6 +338,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"ups": {
"priceEveningDelivery": 134217744,
"priceExpressDelivery": 134218240,
"priceMondayDelivery": 134217760,
"priceMorningDelivery": 134217736,
"priceOnlyRecipient": 134218240,
Expand All @@ -330,6 +353,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"ups:1": {
"priceEveningDelivery": 134479888,
"priceExpressDelivery": 134480384,
"priceMondayDelivery": 134479904,
"priceMorningDelivery": 134479880,
"priceOnlyRecipient": 134480384,
Expand All @@ -344,6 +368,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
"ups:2": {
"priceEveningDelivery": 134742032,
"priceExpressDelivery": 134742528,
"priceMondayDelivery": 134742048,
"priceMorningDelivery": 134742024,
"priceOnlyRecipient": 134742528,
Expand All @@ -358,6 +383,7 @@ exports[`createTestConfiguration > creates a default test configuration with uni
},
},
"priceEveningDelivery": 16,
"priceExpressDelivery": 512,
"priceMondayDelivery": 32,
"priceMorningDelivery": 8,
"priceOnlyRecipient": 512,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const createTestConfiguration = (): InputDeliveryOptionsConfiguration =>
[CarrierSetting.AllowSaturdayDelivery]: true,
[CarrierSetting.AllowSignature]: true,
[CarrierSetting.AllowStandardDelivery]: true,
[CarrierSetting.AllowExpressDelivery]: true,
...Object.entries(TEST_VALUE_MAP_PRICES).reduce((acc, [optionKey, priceValue]) => {
return {...acc, [optionKey]: priceValue};
}, {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {useResolvedDeliveryOptions} from './useResolvedDeliveryOptions';

const CARRIER_IDENTIFIER_WITH_CONTRACT = `${CarrierName.PostNl}:1234`;

const doTestSetup = async (config: RecursivePartial<InputDeliveryOptionsConfiguration> = {}): Promise<void> => {
const setupPostNl = async (config: RecursivePartial<InputDeliveryOptionsConfiguration> = {}): Promise<void> => {
const morning = normalizeDate('2022-01-01T09:00:00');
const standard = normalizeDate('2022-01-01T15:00:00');
const evening = normalizeDate('2022-01-01T20:00:00');

mockGetDeliveryOptions.mockReturnValueOnce(
mockGetDeliveryOptions.mockReturnValue(
Promise.resolve([
{
date: createTimestamp(standard),
Expand Down Expand Up @@ -63,18 +63,56 @@ const doTestSetup = async (config: RecursivePartial<InputDeliveryOptionsConfigur
),
),
);

await waitForDeliveryOptions();
};

const setupUps = async (config: RecursivePartial<InputDeliveryOptionsConfiguration> = {}): Promise<void> => {
const today = normalizeDate('2022-01-01T09:00:00');
const tomorrow = normalizeDate('2022-01-02T09:00:00');
const inTwoDays = normalizeDate('2022-01-03T09:00:00');

mockGetDeliveryOptions.mockReturnValue(
Promise.resolve([
{
date: createTimestamp(today),
possibilities: [
createDeliveryPossibility(tomorrow, {type: DeliveryTypeName.Express}),
createDeliveryPossibility(inTwoDays, {type: DeliveryTypeName.Express}),
createDeliveryPossibility(inTwoDays, {type: DeliveryTypeName.Standard}),
],
},
]),
);

mockDeliveryOptionsConfig(
getMockDeliveryOptionsConfiguration(
assign(
{
[KEY_CONFIG]: {
[KEY_CARRIER_SETTINGS]: {
[CarrierName.Ups]: {
[CarrierSetting.AllowDeliveryOptions]: true,
// Provide standard/express setting via config arg.
},
},
},
},
config,
),
),
);

await waitForDeliveryOptions(CarrierName.Ups);
};

describe('useResolvedDeliveryOptions', () => {
beforeEach(() => {
useResolvedDeliveryOptions.clear();
setActivePinia(createPinia());
});

it('sorts options by time', async () => {
await doTestSetup();
await setupPostNl();

const options = useResolvedDeliveryOptions();

Expand All @@ -90,12 +128,53 @@ describe('useResolvedDeliveryOptions', () => {
]);
});

it('prefers standard delivery over express in the same time window', async () => {
await setupUps({
[KEY_CONFIG]: {
[KEY_CARRIER_SETTINGS]: {
[CarrierName.Ups]: {
[CarrierSetting.AllowStandardDelivery]: true,
[CarrierSetting.AllowExpressDelivery]: true,
},
},
},
});

const options = useResolvedDeliveryOptions();
const resolvedOptions = options.value.map(({carrier, deliveryType}) => ({carrier, deliveryType}));

// It should prefer standard to express on day 2.
expect(resolvedOptions).toEqual([
{carrier: CarrierName.Ups, deliveryType: DeliveryTypeName.Express},
{carrier: CarrierName.Ups, deliveryType: DeliveryTypeName.Standard},
]);
});

it('does not filter out standard delivery when express is disabled', async () => {
await setupUps({
[KEY_CONFIG]: {
[KEY_CARRIER_SETTINGS]: {
[CarrierName.Ups]: {
[CarrierSetting.AllowStandardDelivery]: true,
[CarrierSetting.AllowExpressDelivery]: false,
},
},
},
});

const options = useResolvedDeliveryOptions();

const resolvedOptions = options.value.map(({carrier, deliveryType}) => ({carrier, deliveryType}));

// Verify that it doesn't filter out Standard now
expect(resolvedOptions).toEqual([{carrier: CarrierName.Ups, deliveryType: DeliveryTypeName.Standard}]);
});

it('handles fake delivery', async () => {
// DE is not a delivery country for PostNL.
await doTestSetup({[KEY_ADDRESS]: {cc: 'DE'}});
await setupPostNl({[KEY_ADDRESS]: {cc: 'DE'}});

const options = useResolvedDeliveryOptions();

const resolvedOptions = options.value.map(({carrier, deliveryType}) => ({carrier, deliveryType}));

expect(resolvedOptions).toEqual([
Expand Down
Loading