fix: show an arrives-by date on parcel cards only when the mail gives a latest date

This commit is contained in:
Linus Rath
2026-10-30 05:34:55 +01:00
parent 90d7afc349
commit 916434924c
2 changed files with 10 additions and 1 deletions
@@ -185,6 +185,13 @@ describe('normalizeItems', () => {
});
});
it('takes the expected arrival only from its latest bound', () => {
const parcel = (extra: Record<string, unknown>) => norm({ '@context': ctx, '@type': 'ParcelDelivery', trackingNumber: '1', carrier: 'DHL', ...extra })[0] as Shipment;
// The earliest possible delivery day is not an "arrives by" date.
expect(parcel({ expectedArrivalFrom: '2026-11-03' }).parcels[0].expectedBy).toBeUndefined();
expect(parcel({ expectedArrivalFrom: '2026-11-03', expectedArrivalUntil: '2026-11-05' }).parcels[0].expectedBy).toEqual({ date: '2026-11-05' });
});
it('drops types it does not read', () => {
expect(norm(
{ '@context': ctx, '@type': 'PromotionCard', image: 'https://x.example.com/a.png' },
+3 -1
View File
@@ -357,7 +357,9 @@ function parcel(p: Obj, source: CardSource): Shipment {
const carrier = nameOf(p.carrier) ?? nameOf(p.provider);
const trackingNumber = str(p.trackingNumber);
const trackingUrl = link(p.trackingUrl);
const expectedBy = lenientDate(p.expectedArrivalUntil) ?? lenientDate(p.expectedArrivalFrom);
// Only the latest bound is an "arrives by" date; expectedArrivalFrom is the
// earliest one and would promise too much.
const expectedBy = lenientDate(p.expectedArrivalUntil);
const shipped: Parcel = {
...(carrier ? { carrier } : {}),
...(trackingNumber ? { trackingNumber } : {}),