;;; test-pearl-result.el --- Tests for the query result shape -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Craig Jennings ;; Author: Craig Jennings ;; 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 . ;;; 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