blob: 606c3b0b7a94ecb630ba786b1d38ed1b50ba7cd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
|