aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test-pearl-query.el41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test-pearl-query.el b/tests/test-pearl-query.el
index 87e48b9..b5d2816 100644
--- a/tests/test-pearl-query.el
+++ b/tests/test-pearl-query.el
@@ -147,5 +147,46 @@
"The bulk issues query selects comments, so a populated list shows them."
(should (string-match-p "comments[[:space:]]*{[[:space:]]*nodes" pearl--issues-query)))
+;;; malformed remote page shapes
+
+(ert-deftest test-pearl-query-issues-missing-issues-key-is-empty ()
+ "A success payload lacking data.issues yields an empty result, not a Lisp error."
+ (let (result)
+ (cl-letf (((symbol-function 'pearl--graphql-request-async)
+ (lambda (_q _v success-fn _e)
+ (funcall success-fn '((data . nil))))))
+ (pearl--query-issues-async nil (lambda (r) (setq result r)))
+ (should (eq 'empty (pearl--query-result-status result)))
+ (should-not (pearl--query-result-issues result)))))
+
+(ert-deftest test-pearl-query-view-null-customview-no-lisp-error ()
+ "A response with data.customView nil yields a structured result, not a Lisp error."
+ (let (result)
+ (cl-letf (((symbol-function 'pearl--graphql-request-async)
+ (lambda (_q _v success-fn _e)
+ (funcall success-fn '((data (customView . nil)))))))
+ (pearl--query-view-async "v1" (lambda (r) (setq result r)))
+ ;; a deleted / no-access view must not crash the render boundary
+ (should (pearl--query-result-status result)))))
+
+(ert-deftest test-pearl-page-issues-missing-cursor-does-not-loop ()
+ "has-next-page t with a nil end-cursor terminates (bounded by max-pages), not forever."
+ (let ((calls 0) result (pearl-max-issue-pages 3))
+ (pearl--page-issues
+ (lambda (_after page-cb)
+ (cl-incf calls)
+ (funcall page-cb (list :issues '(((id . "x")))
+ :has-next-page t :end-cursor nil)))
+ (lambda (r) (setq result r))
+ 3)
+ (should (= 3 calls))
+ (should (pearl--query-result-truncated-p result))))
+
+(ert-deftest test-pearl-node-list-non-list-nodes-is-empty ()
+ "A connection whose nodes is neither a vector nor a list yields the empty list."
+ (should (null (pearl--node-list '((nodes . "oops")))))
+ (should (null (pearl--node-list '((nodes . 42)))))
+ (should (null (pearl--node-list nil))))
+
(provide 'test-pearl-query)
;;; test-pearl-query.el ends here