/** * Tests fuer das Liefergebiet. * * Die Frage "darf in dieses Land geliefert werden" entscheidet, ob eine * Bestellung zustande kommt. Ein Fehler in die eine Richtung sperrt zahlende * Kundschaft aus, einer in die andere erzeugt Lieferungen in Laender, fuer * die weder Steuer noch Zoll geklaert sind. */ import { describe, test, expect } from "vitest"; import { DEFAULT_SHIPPING_REGION, EU_COUNTRY_CODES, allowedCountryCodes, findCustomsExcludedArea, isCountryAllowed, parseShippingRegion, } from "./shipping-region"; describe("parseShippingRegion", () => { test("erkennt die beiden gueltigen Werte", () => { expect(parseShippingRegion("DE")).toBe("DE"); expect(parseShippingRegion("EU")).toBe("EU"); }); test("ist unempfindlich gegen Schreibweise und Leerzeichen", () => { expect(parseShippingRegion(" eu ")).toBe("EU"); expect(parseShippingRegion("de")).toBe("DE"); }); test("faellt bei fehlendem oder unsinnigem Wert auf den engsten Zuschnitt zurueck", () => { // Wichtige Richtung: im Zweifel WENIGER Laender, nicht mehr. Ein Shop // liefert nie versehentlich weiter, als er wollte. expect(parseShippingRegion(null)).toBe("DE"); expect(parseShippingRegion("")).toBe("DE"); expect(parseShippingRegion("WELTWEIT")).toBe("DE"); expect(DEFAULT_SHIPPING_REGION).toBe("DE"); }); }); describe("allowedCountryCodes", () => { test('"DE" erlaubt genau ein Land', () => { expect(allowedCountryCodes("DE")).toEqual(["DE"]); }); test('"EU" erlaubt die 27 Mitgliedstaaten, sortiert und ohne Dubletten', () => { const codes = allowedCountryCodes("EU"); expect(codes).toHaveLength(27); expect(codes).toEqual([...codes].sort()); expect(new Set(codes).size).toBe(27); }); test("Drittlaender in Europa sind NICHT enthalten", () => { // Schweiz, Norwegen und das Vereinigte Koenigreich liegen in Europa, sind // aber Zollausland — dorthin zu liefern braucht mehr als einen Haken im // Admin-Bereich. const codes = allowedCountryCodes("EU"); expect(codes).not.toContain("CH"); expect(codes).not.toContain("NO"); expect(codes).not.toContain("GB"); }); test("Griechenland steht als ISO-Code GR, nicht als EL", () => { expect(EU_COUNTRY_CODES as readonly string[]).toContain("GR"); expect(EU_COUNTRY_CODES as readonly string[]).not.toContain("EL"); }); }); describe("isCountryAllowed", () => { test('bei "DE" kommt nur Deutschland durch', () => { expect(isCountryAllowed("DE", "DE")).toBe(true); expect(isCountryAllowed("DE", "AT")).toBe(false); expect(isCountryAllowed("DE", "FR")).toBe(false); }); test('bei "EU" kommen Mitgliedstaaten durch, Drittlaender nicht', () => { expect(isCountryAllowed("EU", "AT")).toBe(true); expect(isCountryAllowed("EU", "DE")).toBe(true); expect(isCountryAllowed("EU", "CH")).toBe(false); expect(isCountryAllowed("EU", "US")).toBe(false); }); test("akzeptiert Kleinschreibung und Leerzeichen aus dem Formular", () => { expect(isCountryAllowed("EU", " at ")).toBe(true); expect(isCountryAllowed("DE", "de")).toBe(true); }); test("ein fehlendes Land ist nie erlaubt", () => { expect(isCountryAllowed("EU", null)).toBe(false); expect(isCountryAllowed("EU", "")).toBe(false); expect(isCountryAllowed("EU", " ")).toBe(false); }); }); describe("findCustomsExcludedArea", () => { test("erkennt die beiden deutschen Gebiete ausserhalb des Zollgebiets", () => { // Der ueberraschende Teil: selbst bei "Nur Deutschland" gibt es // Anschriften, die eine Zollanmeldung braeuchten. expect(findCustomsExcludedArea("DE", "27498")).toBe("Helgoland"); expect(findCustomsExcludedArea("DE", "78266")).toBe("Büsingen am Hochrhein"); }); test("laesst normale deutsche Anschriften durch", () => { expect(findCustomsExcludedArea("DE", "86450")).toBeNull(); expect(findCustomsExcludedArea("DE", "10115")).toBeNull(); }); test("erkennt spanische Sondergebiete", () => { expect(findCustomsExcludedArea("ES", "51001")).toBe("Ceuta"); expect(findCustomsExcludedArea("ES", "52001")).toBe("Melilla"); expect(findCustomsExcludedArea("ES", "38001")).toBe("Kanarische Inseln"); // Festland Spanien bleibt normaler Binnenversand. expect(findCustomsExcludedArea("ES", "28001")).toBeNull(); }); test("unterscheidet gleiche Ziffern in verschiedenen Laendern", () => { // "22" ist in Finnland Åland, in Italien die Provinz Como. Deshalb ist // die Zuordnung je Land und nicht global. expect(findCustomsExcludedArea("FI", "22100")).toBe("Åland"); expect(findCustomsExcludedArea("IT", "22100")).toBeNull(); expect(findCustomsExcludedArea("IT", "22061")).toBe("Campione d'Italia"); }); test("erkennt franzoesische Ueberseegebiete", () => { expect(findCustomsExcludedArea("FR", "97100")).toBe("Französische Überseegebiete"); expect(findCustomsExcludedArea("FR", "75001")).toBeNull(); }); test("Azoren und Madeira sind KEIN Sondergebiet", () => { // Sie gehoeren voll zum Zoll- und Steuergebiet — normaler Binnenversand. expect(findCustomsExcludedArea("PT", "9500-001")).toBeNull(); expect(findCustomsExcludedArea("PT", "9000-001")).toBeNull(); }); test("ist unempfindlich gegen Leerzeichen und Kleinschreibung", () => { expect(findCustomsExcludedArea("de", " 27498 ")).toBe("Helgoland"); expect(findCustomsExcludedArea("NL", "1234 ab")).toBeNull(); }); test("ohne Land oder Postleitzahl gibt es nichts zu melden", () => { expect(findCustomsExcludedArea(null, "27498")).toBeNull(); expect(findCustomsExcludedArea("DE", null)).toBeNull(); }); });