-
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.
- Loading branch information
1 parent
be362d3
commit 521ec94
Showing
10 changed files
with
113 additions
and
11 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
23 changes: 23 additions & 0 deletions
23
apps/delivery-options/src/__tests__/utils/createDeliveryPossibility.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,23 @@ | ||
import {addHours} from 'date-fns'; | ||
import {type DateLike, normalizeDate} from '@vueuse/core'; | ||
import {createDeliveryTimeframe} from '@myparcel-do/shared/testing'; | ||
import {type DeliveryOption} from '@myparcel/sdk'; | ||
import {DeliveryTypeName, PackageTypeName} from '@myparcel/constants'; | ||
|
||
export const createDeliveryPossibility = ( | ||
date: DateLike, | ||
options: Partial<DeliveryOption['possibilities'][number]> = {}, | ||
): DeliveryOption['possibilities'][number] => { | ||
const normalizedDate = normalizeDate(date); | ||
|
||
return { | ||
type: DeliveryTypeName.Standard, | ||
package_type: PackageTypeName.Package, | ||
shipment_options: [], | ||
delivery_time_frames: [ | ||
createDeliveryTimeframe(normalizedDate, 'start'), | ||
createDeliveryTimeframe(addHours(normalizedDate, 1), 'end'), | ||
], | ||
...options, | ||
}; | ||
}; |
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
69 changes: 69 additions & 0 deletions
69
apps/delivery-options/src/composables/useResolvedDeliveryOptions.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,69 @@ | ||
import {describe, it, expect, beforeEach} from 'vitest'; | ||
import {setActivePinia, createPinia} from 'pinia'; | ||
import {normalizeDate} from '@vueuse/core'; | ||
import {mockGetDeliveryOptions} from '@myparcel-do/shared/testing'; | ||
import {KEY_CONFIG, CarrierSetting, KEY_CARRIER_SETTINGS, createTimestamp} from '@myparcel-do/shared'; | ||
import {DeliveryTypeName, CarrierName} from '@myparcel/constants'; | ||
import { | ||
waitForDeliveryOptions, | ||
mockDeliveryOptionsConfig, | ||
getMockDeliveryOptionsConfiguration, | ||
createDeliveryPossibility, | ||
} from '../__tests__'; | ||
import {useResolvedDeliveryOptions} from './useResolvedDeliveryOptions'; | ||
|
||
const mockSetup = async (): Promise<void> => { | ||
mockDeliveryOptionsConfig( | ||
getMockDeliveryOptionsConfiguration({ | ||
[KEY_CONFIG]: { | ||
[KEY_CARRIER_SETTINGS]: { | ||
[CarrierName.PostNl]: { | ||
[CarrierSetting.AllowDeliveryOptions]: true, | ||
[CarrierSetting.AllowMondayDelivery]: true, | ||
[CarrierSetting.AllowSameDayDelivery]: true, | ||
[CarrierSetting.AllowEveningDelivery]: true, | ||
[CarrierSetting.AllowMorningDelivery]: true, | ||
[CarrierSetting.AllowStandardDelivery]: true, | ||
}, | ||
}, | ||
}, | ||
}), | ||
); | ||
|
||
await waitForDeliveryOptions(); | ||
}; | ||
|
||
describe('useResolvedDeliveryOptions', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()); | ||
}); | ||
|
||
it('sorts options by time', async () => { | ||
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( | ||
Promise.resolve([ | ||
{ | ||
date: createTimestamp(standard), | ||
possibilities: [ | ||
createDeliveryPossibility(evening, {type: DeliveryTypeName.Evening}), | ||
createDeliveryPossibility(standard), | ||
createDeliveryPossibility(morning, {type: DeliveryTypeName.Morning}), | ||
], | ||
}, | ||
]), | ||
); | ||
|
||
await mockSetup(); | ||
|
||
const options = useResolvedDeliveryOptions(); | ||
|
||
expect(options.value.map((option) => option.deliveryType)).toEqual([ | ||
DeliveryTypeName.Morning, | ||
DeliveryTypeName.Standard, | ||
DeliveryTypeName.Evening, | ||
]); | ||
}); | ||
}); |
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