diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 14:56:47 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 14:56:47 -0500 |
| commit | 44b7e8e42383a0e2c7024f250c2d16de6b66c652 (patch) | |
| tree | 5dd8ab04a39b3847b03dc4cf7cb1240628366832 /tests/test-pearl-assignee-labels.el | |
| parent | ba58f66332e6a8692d985f4d5478c743fca9bcb7 (diff) | |
| download | pearl-44b7e8e42383a0e2c7024f250c2d16de6b66c652.tar.gz pearl-44b7e8e42383a0e2c7024f250c2d16de6b66c652.zip | |
test: cover field-setter command failure branches
Added ERT tests that the four field setters preserve local org state when the issueUpdate mutation fails (returns :success nil): set-priority keeps the cookie, set-state keeps the TODO keyword and LINEAR-STATE drawer, set-assignee keeps the assignee drawer, set-labels keeps the labels drawer. Each test also asserts the push was attempted with the intended input, so a regression that simply stopped calling the API would still fail rather than pass silently. The commands already behave correctly — this locks it. 357 tests green.
Diffstat (limited to 'tests/test-pearl-assignee-labels.el')
| -rw-r--r-- | tests/test-pearl-assignee-labels.el | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test-pearl-assignee-labels.el b/tests/test-pearl-assignee-labels.el index c70f0ca..7a4a352 100644 --- a/tests/test-pearl-assignee-labels.el +++ b/tests/test-pearl-assignee-labels.el @@ -71,6 +71,20 @@ (test-pearl--in-org "* Plain heading\nno id\n" (should-error (pearl-set-assignee "Craig") :type 'user-error))) +(ert-deftest test-pearl-set-assignee-failure-preserves-drawer () + "A failed assignee push attempts the mutation but leaves the drawer unchanged." + (let (pushed) + (test-pearl--in-org + "*** TODO Title\n:PROPERTIES:\n:LINEAR-ID: a\n:LINEAR-TEAM-ID: team-1\n:LINEAR-ASSIGNEE-ID: old\n:LINEAR-ASSIGNEE-NAME: Someone\n:END:\n" + (cl-letf (((symbol-function 'pearl--resolve-team-id) + (lambda (_kind _name _team &optional _force) "u9")) + ((symbol-function 'pearl--update-issue-async) + (lambda (_id input cb) (setq pushed input) (funcall cb '(:success nil))))) + (pearl-set-assignee "Craig") + (should (string= "u9" (cdr (assoc "assigneeId" pushed)))) + (should (string= "Someone" (org-entry-get nil "LINEAR-ASSIGNEE-NAME"))) + (should (string= "old" (org-entry-get nil "LINEAR-ASSIGNEE-ID"))))))) + ;;; set-labels (ert-deftest test-pearl-set-labels-pushes-ids-and-updates-drawer () @@ -110,5 +124,19 @@ (should-error (pearl-set-labels '("ghost")) :type 'user-error) (should-not pushed))))) +(ert-deftest test-pearl-set-labels-failure-preserves-drawer () + "A failed labels push attempts the mutation but leaves the labels drawer unchanged." + (let (pushed) + (test-pearl--in-org + "*** TODO Title\n:PROPERTIES:\n:LINEAR-ID: a\n:LINEAR-TEAM-ID: team-1\n:LINEAR-LABELS: [bug]\n:END:\n" + (cl-letf (((symbol-function 'pearl--resolve-team-id) + (lambda (_kind name _team &optional _force) + (pcase name ("p1" "l2") (_ nil)))) + ((symbol-function 'pearl--update-issue-async) + (lambda (_id input cb) (setq pushed input) (funcall cb '(:success nil))))) + (pearl-set-labels '("p1")) + (should (equal '("l2") (cdr (assoc "labelIds" pushed)))) + (should (string= "[bug]" (org-entry-get nil "LINEAR-LABELS"))))))) + (provide 'test-pearl-assignee-labels) ;;; test-pearl-assignee-labels.el ends here |
