mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
fix: show an arrives-by date on parcel cards only when the mail gives a latest date
This commit is contained in:
@@ -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' },
|
||||
|
||||
@@ -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 } : {}),
|
||||
|
||||
Reference in New Issue
Block a user