diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 13:44:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 13:44:34 -0500 |
| commit | b081d62276378b3168c92c06153fd59db0589535 (patch) | |
| tree | 9be7f7d22e0c9b4a73432fe744c09bb456c671a9 /tests/test-pearl-api.el | |
| download | pearl-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-api.el')
| -rw-r--r-- | tests/test-pearl-api.el | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/test-pearl-api.el b/tests/test-pearl-api.el new file mode 100644 index 0000000..bf4f45e --- /dev/null +++ b/tests/test-pearl-api.el @@ -0,0 +1,90 @@ +;;; test-pearl-api.el --- Tests for pearl core API layer -*- 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 GraphQL request layer with `request' stubbed at the HTTP +;; boundary: the async entry point routes to success/error correctly and +;; balances the active-request counter; the sync wrapper returns data or nil. + +;;; Code: + +(require 'test-bootstrap (expand-file-name "test-bootstrap.el")) +(require 'testutil-request (expand-file-name "testutil-request.el")) + +(ert-deftest test-pearl-graphql-request-async-success-routes-to-success-fn () + "A successful response is passed to the success function." + (let ((got nil)) + (testutil-linear-with-response '((data (viewer (name . "Me")))) + (pearl--graphql-request-async + "query" nil + (lambda (data) (setq got data)) + (lambda (&rest _) (setq got 'error)))) + (should (equal '((data (viewer (name . "Me")))) got)))) + +(ert-deftest test-pearl-graphql-request-async-error-routes-to-error-fn () + "A transport error is passed to the error function." + (let ((got nil)) + (testutil-linear-with-error "boom" + (pearl--graphql-request-async + "query" nil + (lambda (_d) (setq got 'success)) + (lambda (err _r _d) (setq got err)))) + (should (equal "boom" got)))) + +(ert-deftest test-pearl-graphql-request-async-balances-active-counter-on-success () + "The active-request counter returns to its starting value after success." + (let ((pearl--active-requests 0)) + (testutil-linear-with-response '((data)) + (pearl--graphql-request-async "q" nil #'ignore #'ignore)) + (should (= 0 pearl--active-requests)))) + +(ert-deftest test-pearl-graphql-request-async-nil-response-does-not-error () + "A transport error with a nil response routes to error-fn without throwing. + +The error handler logs the response status code; that read must be guarded +so a nil response (some transport failures) doesn't crash inside the handler." + (let ((pearl-api-key "test-key") (got nil)) + (cl-letf (((symbol-function 'request) + (lambda (_url &rest args) + (funcall (plist-get args :error) + :error-thrown "boom" :response nil :data nil)))) + (pearl--graphql-request-async + "q" nil #'ignore (lambda (err _r _d) (setq got err)))) + (should (equal "boom" got)))) + +(ert-deftest test-pearl-graphql-request-async-balances-active-counter-on-error () + "The active-request counter returns to its starting value after an error." + (let ((pearl--active-requests 0)) + (testutil-linear-with-error "boom" + (pearl--graphql-request-async "q" nil #'ignore #'ignore)) + (should (= 0 pearl--active-requests)))) + +(ert-deftest test-pearl-graphql-request-sync-returns-data () + "The synchronous wrapper returns the parsed response." + (testutil-linear-with-response '((data (x . 1))) + (should (equal '((data (x . 1))) (pearl--graphql-request "q"))))) + +(ert-deftest test-pearl-graphql-request-sync-error-returns-nil () + "The synchronous wrapper returns nil on a transport error." + (testutil-linear-with-error "boom" + (should (null (pearl--graphql-request "q"))))) + +(provide 'test-pearl-api) +;;; test-pearl-api.el ends here |
