diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-28 18:10:17 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-28 19:09:22 -0500 |
| commit | dc0db0f0e12d8af6d1d54a5dde1cd16cf890a33d (patch) | |
| tree | 9d174e136d62981c1bded06fe423d08bddc91e04 /tests/test-gloss-fetch--definitions-404-returns-no-defs.el | |
| parent | 3a846506399dc12ab219bfa8047947c122dd1d04 (diff) | |
| download | gloss-dc0db0f0e12d8af6d1d54a5dde1cd16cf890a33d.tar.gz gloss-dc0db0f0e12d8af6d1d54a5dde1cd16cf890a33d.zip | |
test: add gloss-fetch test suite (red phase)
Eight test files cover the network layer's public and internal contract.
The boundary mock is `url-retrieve-synchronously', wrapped by a small
`testutil-gloss-fetch' helper that builds response buffers in the shape
the url library returns.
Tests cover the 200 happy paths (anaphora and SBIR fixtures), 404 to
:no-defs, 5xx and 4xx-other and malformed JSON to :server-error, 429 to
:rate-limited, nil-from-url to :unreachable, the libxml availability
probe (one-shot, signals user-error when absent), the registry walker
ordering, and the pure HTML strip helper across N/B/E.
Tests fail on missing `gloss-fetch--*' functions, as expected for red
phase.
Diffstat (limited to 'tests/test-gloss-fetch--definitions-404-returns-no-defs.el')
| -rw-r--r-- | tests/test-gloss-fetch--definitions-404-returns-no-defs.el | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-gloss-fetch--definitions-404-returns-no-defs.el b/tests/test-gloss-fetch--definitions-404-returns-no-defs.el new file mode 100644 index 0000000..d8cd257 --- /dev/null +++ b/tests/test-gloss-fetch--definitions-404-returns-no-defs.el @@ -0,0 +1,48 @@ +;;; test-gloss-fetch--definitions-404-returns-no-defs.el --- 404 path -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; HTTP 404 from a source maps to :no-defs. When every source returns +;; :no-defs, the user-facing rollup is :empty with the source listed +;; under :no-defs and nothing under :failed. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'gloss-fetch) +(require 'testutil-gloss-fetch) + +(ert-deftest test-gloss-fetch-definitions-404-rolls-up-to-empty-no-defs () + "Normal: a 404 from the only source rolls up to (:empty :no-defs (wiktionary) :failed nil)." + (gloss-fetch-test--with-mocked-url + (lambda (_url) + (gloss-fetch-test--status-response "HTTP/1.1 404 Not Found" + "{\"detail\":\"Page not found\"}")) + (let ((result (gloss-fetch-definitions "asdf-not-a-word"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :no-defs))) + (should-not (plist-get result :failed))))) + +(ert-deftest test-gloss-fetch-definitions-200-empty-rolls-up-to-empty-no-defs () + "Boundary: a 200 with an empty JSON object also maps to :no-defs." + (gloss-fetch-test--with-mocked-url + (lambda (_url) (gloss-fetch-test--ok-response "{}")) + (let ((result (gloss-fetch-definitions "term"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :no-defs))) + (should-not (plist-get result :failed))))) + +(ert-deftest test-gloss-fetch-definitions-200-no-english-rolls-up-to-no-defs () + "Boundary: a 200 response with only non-English keys maps to :no-defs." + ;; v1 ignores everything but the en key per the design doc. + (let ((body "{\"fr\":[{\"partOfSpeech\":\"Noun\",\"language\":\"French\",\"definitions\":[{\"definition\":\"Un mot.\"}]}]}")) + (gloss-fetch-test--with-mocked-url + (lambda (_url) (gloss-fetch-test--ok-response body)) + (let ((result (gloss-fetch-definitions "term"))) + (should (eq (car result) :empty)) + (should (member 'wiktionary (plist-get result :no-defs))))))) + +(provide 'test-gloss-fetch--definitions-404-returns-no-defs) +;;; test-gloss-fetch--definitions-404-returns-no-defs.el ends here |
