From 3e263765843a67cccc4618bd47d5669b980de2a2 Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Mon, 9 Mar 2026 07:55:17 +0000 Subject: [PATCH] Fix slug lookup and add regression test --- hdyc-svelte/src/lib/data/calculators.ts | 5 +++++ migrate.py | 5 +++++ tests/test_apothecary_page.py | 27 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/test_apothecary_page.py diff --git a/hdyc-svelte/src/lib/data/calculators.ts b/hdyc-svelte/src/lib/data/calculators.ts index 6143633..36b6077 100644 --- a/hdyc-svelte/src/lib/data/calculators.ts +++ b/hdyc-svelte/src/lib/data/calculators.ts @@ -3167,6 +3167,11 @@ export const calculators: CalculatorDef[] = [ ]; +const slugIndex: Map = new Map( + calculators.map(calc => [calc.slug, calc]) +); + + export function getCalculatorBySlug(slug: string): CalculatorDef | undefined { return slugIndex.get(slug); } diff --git a/migrate.py b/migrate.py index da28586..46844ac 100644 --- a/migrate.py +++ b/migrate.py @@ -463,6 +463,11 @@ export const calculators: CalculatorDef[] = [ out += """ ]; + +const slugIndex: Map = new Map( + calculators.map(calc => [calc.slug, calc]) +); + """ out += """ diff --git a/tests/test_apothecary_page.py b/tests/test_apothecary_page.py new file mode 100644 index 0000000..543913d --- /dev/null +++ b/tests/test_apothecary_page.py @@ -0,0 +1,27 @@ +import urllib.error +import urllib.request +import unittest + +URL = 'https://howdoyouconvert.com/apothecary-ounces-to-amu' + + +class ApothecaryPageTests(unittest.TestCase): + def test_apothecary_page_returns_success(self) -> None: + """The published URL should return a 200 so the calculator page stays healthy.""" + request = urllib.request.Request( + URL, + headers={ + 'User-Agent': 'Mozilla/5.0', + 'Accept': 'text/html,application/xhtml+xml', + }, + ) + + try: + with urllib.request.urlopen(request, timeout=15) as response: + status = response.getcode() + except urllib.error.HTTPError as exc: + self.fail(f'{URL} returned HTTP {exc.code} ({exc.reason})') + except urllib.error.URLError as exc: + self.fail(f'{URL} could not be fetched: {exc}') + + self.assertEqual(status, 200, f'{URL} returned {status}')