aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-pearl-resolve.el59
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