diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 15:13:53 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 15:13:53 -0500 |
| commit | 6fca176d45b91d281bab36b51260e0ca1a788084 (patch) | |
| tree | b0da7462ed8056256b0dfce4f4975c8760a8a66a | |
| parent | 2e87942b8bdff716cef7af9ca99fce8ef1588a5c (diff) | |
| download | pearl-6fca176d45b91d281bab36b51260e0ca1a788084.tar.gz pearl-6fca176d45b91d281bab36b51260e0ca1a788084.zip | |
test: cover cache and resolver failure cases
Added ERT tests that the per-team collection cache and the resolvers fail soft: pearl--team-collection returns nil and caches nothing on a malformed (missing nodes) or nil response, so a retry refetches and a later success populates the cache; pearl--resolve-team-id returns nil rather than erroring when its backing fetch fails; pearl--custom-views likewise does not cache nil and recovers on a later call. Also dropped a stale pearl--cache-issues binding from this file's cache-reset macro — that variable was removed earlier. 371 tests green.
| -rw-r--r-- | tests/test-pearl-resolve.el | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/tests/test-pearl-resolve.el b/tests/test-pearl-resolve.el index d8dda7d..0812f94 100644 --- a/tests/test-pearl-resolve.el +++ b/tests/test-pearl-resolve.el @@ -35,8 +35,7 @@ `(let ((pearl-api-key "test-key") (pearl--cache-team-collections nil) (pearl--cache-states nil) - (pearl--cache-teams nil) - (pearl--cache-issues nil)) + (pearl--cache-teams nil)) ,@body)) (defmacro test-pearl--counting-request (data counter &rest body) @@ -137,5 +136,61 @@ (should-not pearl--cache-states) (should-not pearl--cache-teams))) +;;; failure / malformed cases + +(ert-deftest test-pearl-team-collection-malformed-returns-nil-no-cache () + "A response missing the collection nodes returns nil and caches nothing." + (test-pearl--with-clean-caches + (let ((calls 0)) + (test-pearl--counting-request '((data (team nil))) calls + (should-not (pearl--team-collection 'projects "team-1")) + (should-not pearl--cache-team-collections) + ;; nothing cached, so a second call refetches + (pearl--team-collection 'projects "team-1") + (should (= 2 calls)))))) + +(ert-deftest test-pearl-team-collection-nil-response-returns-nil () + "A failed request (nil response) returns nil and caches nothing, without erroring." + (test-pearl--with-clean-caches + (let ((calls 0)) + (test-pearl--counting-request nil calls + (should-not (pearl--team-collection 'members "team-1")) + (should-not pearl--cache-team-collections))))) + +(ert-deftest test-pearl-team-collection-recovers-after-failure () + "A failed fetch caches nothing, so a later successful fetch populates the cache." + (test-pearl--with-clean-caches + (let ((responses (list nil + '((data (team (projects (nodes . [((id . "p1") (name . "Foo"))])))))))) + (cl-letf (((symbol-function 'request) + (lambda (_url &rest args) + (let ((cb (plist-get args :success)) (d (pop responses))) + (when cb (funcall cb :data d)))))) + (should-not (pearl--team-collection 'projects "team-1")) + (let ((second (pearl--team-collection 'projects "team-1"))) + (should (= 1 (length second))) + (should (string= "p1" (cdr (assoc 'id (car second)))))))))) + +(ert-deftest test-pearl-resolve-failed-collection-is-nil () + "When the backing collection fetch fails (empty), resolution returns nil, not an error." + (test-pearl--with-clean-caches + (cl-letf (((symbol-function 'pearl--team-collection) (lambda (&rest _) nil))) + (should-not (pearl--resolve-team-id 'labels "bug" "team-1"))))) + +(ert-deftest test-pearl-custom-views-recovers-after-failure () + "A failed custom-views fetch caches nothing; a later call recovers." + (let ((pearl-api-key "test-key") + (pearl--cache-views nil) + (responses (list nil + '((data (customViews (nodes . [((id . "v1") (name . "My View") (url . "u"))]))))))) + (cl-letf (((symbol-function 'request) + (lambda (_url &rest args) + (let ((cb (plist-get args :success)) (d (pop responses))) + (when cb (funcall cb :data d)))))) + (should-not (pearl--custom-views)) + (should-not pearl--cache-views) + (let ((views (pearl--custom-views))) + (should (= 1 (length views))))))) + (provide 'test-pearl-resolve) ;;; test-pearl-resolve.el ends here |
