aboutsummaryrefslogtreecommitdiff
path: root/tests/test-pearl-result.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-24 13:44:34 -0500
committerCraig Jennings <c@cjennings.net>2026-05-24 13:44:34 -0500
commitb081d62276378b3168c92c06153fd59db0589535 (patch)
tree9be7f7d22e0c9b4a73432fe744c09bb456c671a9 /tests/test-pearl-result.el
downloadpearl-b081d62276378b3168c92c06153fd59db0589535.tar.gz
pearl-b081d62276378b3168c92c06153fd59db0589535.zip
feat: pearl — manage Linear issues from org-mode
Pearl fetches Linear issues into an org file and syncs edits back. It covers list / custom views / saved queries, per-issue and bulk rendering with comments inline, conflict-aware sync of descriptions, titles, and comments, field commands for priority / state / assignee / labels, and a transient dispatch menu. The render folds to a scannable outline and nests issues under a sortable parent. Based on and inspired by Gael Blanchemain's linear-emacs.
Diffstat (limited to 'tests/test-pearl-result.el')
-rw-r--r--tests/test-pearl-result.el98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/test-pearl-result.el b/tests/test-pearl-result.el
new file mode 100644
index 0000000..606c3b0
--- /dev/null
+++ b/tests/test-pearl-result.el
@@ -0,0 +1,98 @@
+;;; test-pearl-result.el --- Tests for the query result shape -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2026 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Tests for the tagged query-result shape and `--classify-response': the five
+;; statuses (ok / empty / invalid-filter / request-failed / graphql-failed),
+;; the ok/error predicates, the GraphQL error-message extraction (vector and
+;; list forms), and the truncated flag. All pure -- no network.
+
+;;; Code:
+
+(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
+
+;;; classify-response
+
+(ert-deftest test-pearl-result-classify-nil-is-request-failed ()
+ "A nil response is a transport failure."
+ (let ((r (pearl--classify-response nil)))
+ (should (eq 'request-failed (pearl--query-result-status r)))
+ (should (pearl--query-result-error-p r))
+ (should (stringp (pearl--query-result-message r)))))
+
+(ert-deftest test-pearl-result-classify-errors-is-graphql-failed ()
+ "A response carrying errors is a GraphQL failure with the message extracted."
+ (let ((r (pearl--classify-response '((errors . (((message . "bad filter"))))))))
+ (should (eq 'graphql-failed (pearl--query-result-status r)))
+ (should (string= "bad filter" (pearl--query-result-message r)))))
+
+(ert-deftest test-pearl-result-classify-errors-vector-form ()
+ "Errors as a vector (the live API shape) still yield the first message."
+ (let ((r (pearl--classify-response '((errors . [((message . "nope"))])))))
+ (should (eq 'graphql-failed (pearl--query-result-status r)))
+ (should (string= "nope" (pearl--query-result-message r)))))
+
+(ert-deftest test-pearl-result-classify-data-with-issues-is-ok ()
+ "A data response with issues is ok and carries the issues."
+ (let ((r (pearl--classify-response '((data (issues))) '(i1 i2))))
+ (should (eq 'ok (pearl--query-result-status r)))
+ (should (pearl--query-result-ok-p r))
+ (should (equal '(i1 i2) (pearl--query-result-issues r)))))
+
+(ert-deftest test-pearl-result-classify-data-without-issues-is-empty ()
+ "A data response with no issues is empty, not a failure."
+ (let ((r (pearl--classify-response '((data (issues))) '())))
+ (should (eq 'empty (pearl--query-result-status r)))
+ (should (pearl--query-result-ok-p r))
+ (should-not (pearl--query-result-error-p r))))
+
+(ert-deftest test-pearl-result-classify-no-data-no-errors-is-request-failed ()
+ "A response with neither data nor errors is treated as malformed/transport."
+ (let ((r (pearl--classify-response '((extensions . nil)))))
+ (should (eq 'request-failed (pearl--query-result-status r)))))
+
+(ert-deftest test-pearl-result-classify-carries-truncated-flag ()
+ "The truncated flag is carried through on a successful result."
+ (let ((r (pearl--classify-response '((data (issues))) '(i1) t)))
+ (should (pearl--query-result-truncated-p r))))
+
+(ert-deftest test-pearl-result-classify-ok-not-truncated-by-default ()
+ "Without the truncated argument the flag is nil."
+ (let ((r (pearl--classify-response '((data (issues))) '(i1))))
+ (should-not (pearl--query-result-truncated-p r))))
+
+;;; invalid-filter
+
+(ert-deftest test-pearl-result-invalid-filter ()
+ "An invalid-filter result is an error carrying its message."
+ (let ((r (pearl--invalid-filter-result "bad :priority")))
+ (should (eq 'invalid-filter (pearl--query-result-status r)))
+ (should (pearl--query-result-error-p r))
+ (should-not (pearl--query-result-ok-p r))
+ (should (string= "bad :priority" (pearl--query-result-message r)))))
+
+;;; error-message extraction
+
+(ert-deftest test-pearl-result-graphql-error-message-nil-when-absent ()
+ "With no errors key, the error-message extractor returns nil."
+ (should (null (pearl--graphql-error-message '((data (issues)))))))
+
+(provide 'test-pearl-result)
+;;; test-pearl-result.el ends here