orders: share the merchant tidy, and fix two bugs the corpus run found (board 212)
ci / lint-test (push) Successful in 41s
ci / lint-test (push) Successful in 41s
The tidy existed but lived inside the list page, so the DETAIL page never had it: following a row through showed "Apple" becoming "Apple Pty Ltd." Moved to src/lib/merchant-label.ts and applied on both surfaces. Running it over all 1,451 distinct merchant names — rather than over examples — turned up two real defects: Coburger & Co -> "Coburger &" eBay Commerce Australia Pty Ltd. -> "EBay Commerce Australia" The first strips a suffix that is part of the brand and leaves a dangling connector. The second is the capitalisation rule firing on "starts with a lower-case letter" when what it means is "is a bare domain" — mangling a brand that is deliberately lower-cased. Both are now guarded, and re-running over the full corpus reports 170 names tidied and 0 defects. PRESENTATION ONLY. It merges nothing and must never decide two rows are the same merchant. Amazon.in stays Amazon.in — a different marketplace with different currency and geography, not a name variant — and there is a test asserting it can never equal amazon.com.au. Kogan.com, GOG.com, AliExpress.com and Catch.com.au are real brand names containing a TLD and are left alone. Real unification is the merchant-alias bridge, ticket 176, which has already merged what can be merged safely. The five names that read alike after tidying (ebay/eBay/eBay Inc., menulog/Menulog Pty Ltd, deliveroo/Deliveroo, grab/Grab, paypal/PayPal) are genuinely one merchant each, so reading alike is correct. Lower-case platform SLUGS are deliberately not capitalised: "ebay" -> "Ebay" is wrong, and getting it right is the registry's job, not the stylesheet's.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { tidyMerchant } from "@/lib/merchant-label";
|
||||
|
||||
/**
|
||||
* Board 212. Every fixture below is a real `display_name` from order_feed.
|
||||
* The cases that matter most are the ones that must NOT change: this is a
|
||||
* presentational tidy and merging anything here would be a data error wearing
|
||||
* a stylesheet.
|
||||
*/
|
||||
describe("tidyMerchant", () => {
|
||||
it("capitalises a bare domain used as a name", () => {
|
||||
expect(tidyMerchant("amazon.com.au")).toBe("Amazon.com.au");
|
||||
expect(tidyMerchant("cdkeys.com")).toBe("Cdkeys.com");
|
||||
});
|
||||
|
||||
it("NEVER merges the country marketplaces", () => {
|
||||
// The single most important assertion in this file. Amazon.in is a
|
||||
// different marketplace with different currency and geography, and 289
|
||||
// orders sit behind it.
|
||||
expect(tidyMerchant("Amazon.in")).toBe("Amazon.in");
|
||||
expect(tidyMerchant("amazon.com.au")).not.toBe(tidyMerchant("Amazon.in"));
|
||||
});
|
||||
|
||||
it("leaves real brand names that contain a TLD alone", () => {
|
||||
for (const brand of ["Kogan.com", "GOG.com", "AliExpress.com", "Catch.com.au", "GeekBuying.com"]) {
|
||||
expect(tidyMerchant(brand)).toBe(brand);
|
||||
}
|
||||
});
|
||||
|
||||
it("does not uppercase a deliberately lower-cased brand", () => {
|
||||
// The bug the corpus run found: gating on "starts lower-case" rather than
|
||||
// on "is a bare domain" turned this into "EBay Commerce Australia".
|
||||
expect(tidyMerchant("eBay Commerce Australia Pty Ltd.")).toBe("eBay Commerce Australia");
|
||||
expect(tidyMerchant("iRobot Australia Pty Ltd")).toBe("iRobot Australia");
|
||||
});
|
||||
|
||||
it("drops trailing corporate suffixes", () => {
|
||||
expect(tidyMerchant("Apple Pty Ltd.")).toBe("Apple");
|
||||
expect(tidyMerchant("Microsoft Pty. Limited")).toBe("Microsoft");
|
||||
expect(tidyMerchant("Meta Platforms, Inc.")).toBe("Meta Platforms");
|
||||
expect(tidyMerchant("Domino's Pizza Enterprises Limited")).toBe("Domino's Pizza Enterprises");
|
||||
expect(tidyMerchant("Blinks Labs GmbH")).toBe("Blinks Labs");
|
||||
expect(tidyMerchant("Rasier New Zealand Limited")).toBe("Rasier New Zealand");
|
||||
});
|
||||
|
||||
it("strips two suffixes when a name carries two", () => {
|
||||
expect(tidyMerchant("Samsung Electronics Co. Ltd.")).toBe("Samsung Electronics");
|
||||
expect(tidyMerchant("DiDi Mobility Information Technology Pte. Ltd."))
|
||||
.toBe("DiDi Mobility Information Technology");
|
||||
});
|
||||
|
||||
it("does not leave a dangling connector", () => {
|
||||
// 'Co' is part of this brand. Stripping it produced "Coburger &".
|
||||
expect(tidyMerchant("Coburger & Co")).toBe("Coburger & Co");
|
||||
});
|
||||
|
||||
it("keeps a name that would be reduced to almost nothing", () => {
|
||||
// "UT" is too short to stand on its own; better scruffy than cryptic.
|
||||
expect(tidyMerchant("UT LLC")).toBe("UT LLC");
|
||||
});
|
||||
|
||||
it("normalises whitespace and tolerates junk", () => {
|
||||
expect(tidyMerchant(" Yaffa Media Pty Ltd ")).toBe("Yaffa Media");
|
||||
expect(tidyMerchant("")).toBe("");
|
||||
});
|
||||
|
||||
it("is idempotent", () => {
|
||||
for (const n of ["amazon.com.au", "Apple Pty Ltd.", "Coburger & Co", "Amazon.in"]) {
|
||||
expect(tidyMerchant(tidyMerchant(n))).toBe(tidyMerchant(n));
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user