From 6161ddc9de0759e2eadb14719ccc191c0978c043 Mon Sep 17 00:00:00 2001 From: siddharthd Date: Mon, 27 Jul 2026 11:33:37 +1000 Subject: [PATCH] fix(orders): don't restate a platform the merchant already names Trip rows read "Order - Uber Trip (Uber)". The suffix exists so you can tell where to go and look; when the merchant is literally "Uber Trip" it says nothing. What identifies a trip is its two addresses, and those are in the Order details panel. Existing rows updated in prod. --- src/__tests__/unit/order-ingestion.test.ts | 17 +++++++++++++++++ src/lib/order-ingestion.ts | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/__tests__/unit/order-ingestion.test.ts b/src/__tests__/unit/order-ingestion.test.ts index 059c2ba..484945c 100644 --- a/src/__tests__/unit/order-ingestion.test.ts +++ b/src/__tests__/unit/order-ingestion.test.ts @@ -6,6 +6,7 @@ import { validateOrderTotals, resolveCategory, NotAReceiptError, + orderDescription, type MessageMeta, type ParsedOrder, } from "../../lib/order-ingestion"; @@ -303,3 +304,19 @@ describe("Uber trips", () => { expect(() => trip("ut-summary")).toThrow(NotAReceiptError); }); }); + +describe("orderDescription", () => { + it("names the platform", () => { + expect(orderDescription("doordash", "Mad Mex")).toBe("Order - Mad Mex (DoorDash)"); + expect(orderDescription("ubereats", "Coles (Wyndham Vale)")).toBe( + "Order - Coles (Wyndham Vale) (Uber Eats)" + ); + }); + + it("does not restate a platform the merchant already names", () => { + // A trip's merchant is literally "Uber Trip"; "(Uber)" after it says + // nothing. What identifies a trip is its addresses, and those live in the + // Order details panel. + expect(orderDescription("uber", "Uber Trip")).toBe("Order - Uber Trip"); + }); +}); diff --git a/src/lib/order-ingestion.ts b/src/lib/order-ingestion.ts index 6e9b016..87f5a68 100644 --- a/src/lib/order-ingestion.ts +++ b/src/lib/order-ingestion.ts @@ -27,7 +27,12 @@ export const PLATFORM_LABEL: Record = { * platform is the one thing the parser always knows and used to discard. */ export function orderDescription(platform: ParsedOrder["platform"], merchant: string): string { - return `Order - ${merchant} (${PLATFORM_LABEL[platform]})`; + const label = PLATFORM_LABEL[platform]; + // A trip's merchant is literally "Uber Trip", so the suffix would restate it + // — "Order - Uber Trip (Uber)". The addresses that actually identify a trip + // are in the Order details panel, not squeezed into the description. + if (merchant.toLowerCase().includes(label.toLowerCase())) return `Order - ${merchant}`; + return `Order - ${merchant} (${label})`; } export interface IngestResult {