diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 15:08:09 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 15:08:09 -0500 |
| commit | 2e87942b8bdff716cef7af9ca99fce8ef1588a5c (patch) | |
| tree | c9f10ae4ed119fb8aca80e25aad42a74058dcfca /tests/test-pearl-query.el | |
| parent | 5f72705cf8534543134da907a26069fff97b799c (diff) | |
| download | pearl-2e87942b8bdff716cef7af9ca99fce8ef1588a5c.tar.gz pearl-2e87942b8bdff716cef7af9ca99fce8ef1588a5c.zip | |
test: cover malformed remote page shapes in the query pager
Added ERT tests that the query and pager layer degrades gracefully on bad payloads instead of erroring: a success response missing data.issues yields an empty result; data.customView nil yields a structured result with no Lisp error; a page reporting has-next-page with a nil end-cursor terminates at the max-pages bound rather than looping; and pearl--node-list returns the empty list for non-list or non-vector nodes. 366 tests green.
Diffstat (limited to 'tests/test-pearl-query.el')
| -rw-r--r-- | tests/test-pearl-query.el | 41 |
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 |
