aboutsummaryrefslogtreecommitdiff
path: root/tests/test-pearl-issues.el
blob: 0976e0a25f848d29caab56eda0ef1a84615120cd (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
;;; test-pearl-issues.el --- Tests for pearl issue fetch/create -*- 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 issue creation with `request' stubbed, focused on
;; `pearl--created-issue' (the success-checking helper that prevents
;; phantom "created" reports) and the create-issue async path.

;;; Code:

(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
(require 'testutil-request (expand-file-name "testutil-request.el"))

;;; pearl--created-issue (pure)

(ert-deftest test-pearl-created-issue-success-returns-node ()
  "A successful create returns the issue node."
  (let ((issue (pearl--created-issue
                '((data (issueCreate (success . t)
                                     (issue (id . "i1") (identifier . "ENG-1") (title . "T"))))))))
    (should (string-equal "ENG-1" (cdr (assoc 'identifier issue))))))

(ert-deftest test-pearl-created-issue-soft-fail-returns-nil ()
  "A soft failure (success=false, issue=null) returns nil, not a phantom node."
  (should (null (pearl--created-issue
                 '((data (issueCreate (success . :json-false) (issue))))))))

(ert-deftest test-pearl-created-issue-graphql-error-returns-nil ()
  "A GraphQL error body (no data) returns nil."
  (should (null (pearl--created-issue '((errors . (((message . "bad")))))))))

(ert-deftest test-pearl-created-issue-empty-response-returns-nil ()
  "A nil/empty response returns nil."
  (should (null (pearl--created-issue nil))))

;;; pearl-create-issue-async

(ert-deftest test-pearl-create-issue-async-success-passes-issue ()
  "A successful create passes the issue node to the callback."
  (let ((got 'unset))
    (testutil-linear-with-response
        '((data (issueCreate (success . t)
                             (issue (id . "i1") (identifier . "ENG-1") (title . "T")))))
      (pearl-create-issue-async "T" "" "team" (lambda (i) (setq got i))))
    (should (string-equal "ENG-1" (cdr (assoc 'identifier got))))))

(ert-deftest test-pearl-create-issue-async-soft-fail-passes-nil ()
  "A soft failure passes nil to the callback rather than a phantom issue."
  (let ((got 'unset))
    (testutil-linear-with-response
        '((data (issueCreate (success . :json-false) (issue))))
      (pearl-create-issue-async "T" "" "team" (lambda (i) (setq got i))))
    (should (null got))))

(provide 'test-pearl-issues)
;;; test-pearl-issues.el ends here