aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-pearl-mapping.el10
-rw-r--r--tests/test-pearl-save.el64
2 files changed, 69 insertions, 5 deletions
diff --git a/tests/test-pearl-mapping.el b/tests/test-pearl-mapping.el
index d9854cb..17eff82 100644
--- a/tests/test-pearl-mapping.el
+++ b/tests/test-pearl-mapping.el
@@ -124,11 +124,11 @@ outlive a change to `pearl-state-to-todo-mapping'."
(should (string-equal "Medium" (pearl--get-linear-priority-name 3)))
(should (string-equal "Low" (pearl--get-linear-priority-name 4))))
-(ert-deftest test-pearl-get-linear-priority-name-nil-and-unknown-default-medium ()
- "A nil, zero, or out-of-range priority falls back to Medium."
- (should (string-equal "Medium" (pearl--get-linear-priority-name 0)))
- (should (string-equal "Medium" (pearl--get-linear-priority-name nil)))
- (should (string-equal "Medium" (pearl--get-linear-priority-name 99))))
+(ert-deftest test-pearl-get-linear-priority-name-none-and-unknown ()
+ "Zero (None), nil, and out-of-range priorities read as None."
+ (should (string-equal "None" (pearl--get-linear-priority-name 0)))
+ (should (string-equal "None" (pearl--get-linear-priority-name nil)))
+ (should (string-equal "None" (pearl--get-linear-priority-name 99))))
;;; pearl-get-priorities
diff --git a/tests/test-pearl-save.el b/tests/test-pearl-save.el
index edd2c2d..8df7b3b 100644
--- a/tests/test-pearl-save.el
+++ b/tests/test-pearl-save.el
@@ -397,6 +397,70 @@ the conflict choice (stubbed). Returns (:outcome :fetched :pushed :applied
(should (string= "a2" pushed))
(should (string= "a2" (org-entry-get marker "LINEAR-ASSIGNEE-ID-SYNCED")))))))
+;;; --save-priority-field / --save-state-field / --save-labels-field
+
+(ert-deftest test-pearl-save-priority-clean-push-advances-baseline ()
+ "A cookie-changed priority with an unmoved remote pushes and advances LINEAR-PRIORITY."
+ (test-pearl-save--in-rendered
+ '(:id "u" :identifier "ENG-1" :title "t" :priority 2
+ :state (:id "s1" :name "Todo") :description "body")
+ (org-back-to-heading t)
+ (let ((org-priority-highest ?A) (org-priority-lowest ?D))
+ (org-priority ?C)) ; [#B] (2) -> [#C] (3)
+ (let ((marker (point-marker)) outcome pushed)
+ (cl-letf (((symbol-function 'pearl--fetch-issue-async)
+ (lambda (_id cb) (funcall cb '((priority . 2))))) ; remote unmoved
+ ((symbol-function 'pearl--update-issue-async)
+ (lambda (_id input cb)
+ (setq pushed (cdr (assoc "priority" input)))
+ (funcall cb '(:success t)))))
+ (pearl--save-priority-field marker (lambda (o) (setq outcome o)))
+ (should (eq 'pushed (plist-get outcome :status)))
+ (should (eql 3 pushed))
+ (should (string= "3" (org-entry-get marker "LINEAR-PRIORITY")))))))
+
+(ert-deftest test-pearl-save-state-picker-clean-push-advances-baseline ()
+ "A picker-changed state with an unmoved remote pushes stateId and advances the baseline."
+ (test-pearl-save--in-rendered
+ '(:id "u" :identifier "ENG-1" :title "t" :priority 2
+ :state (:id "s1" :name "Todo") :description "body")
+ (org-back-to-heading t)
+ (org-entry-put nil "LINEAR-STATE-ID" "s2") ; the picker chose another state
+ (let ((marker (point-marker)) outcome pushed)
+ (cl-letf (((symbol-function 'pearl--fetch-issue-async)
+ (lambda (_id cb) (funcall cb '((state (id . "s1") (name . "Todo"))))))
+ ((symbol-function 'pearl--update-issue-async)
+ (lambda (_id input cb)
+ (setq pushed (cdr (assoc "stateId" input)))
+ (funcall cb '(:success t)))))
+ (pearl--save-state-field marker (lambda (o) (setq outcome o)))
+ (should (eq 'pushed (plist-get outcome :status)))
+ (should (string= "s2" pushed))
+ (should (string= "s2" (org-entry-get marker "LINEAR-STATE-ID-SYNCED")))))))
+
+(ert-deftest test-pearl-save-labels-clean-push-advances-baseline ()
+ "A changed label set with an unmoved remote pushes labelIds and advances the baseline."
+ (test-pearl-save--in-rendered
+ '(:id "u" :identifier "ENG-1" :title "t" :priority 2
+ :state (:id "s1" :name "Todo")
+ :labels ((:id "l1" :name "bug") (:id "l2" :name "backend"))
+ :description "body")
+ (org-back-to-heading t)
+ (org-entry-put nil "LINEAR-LABEL-IDS" "l1 l3") ; dropped l2, added l3
+ (let ((marker (point-marker)) outcome pushed)
+ (cl-letf (((symbol-function 'pearl--fetch-issue-async)
+ (lambda (_id cb)
+ (funcall cb '((labels (nodes ((id . "l1") (name . "bug"))
+ ((id . "l2") (name . "backend"))))))))
+ ((symbol-function 'pearl--update-issue-async)
+ (lambda (_id input cb)
+ (setq pushed (cdr (assoc "labelIds" input)))
+ (funcall cb '(:success t)))))
+ (pearl--save-labels-field marker (lambda (o) (setq outcome o)))
+ (should (eq 'pushed (plist-get outcome :status)))
+ (should (equal ["l1" "l3"] pushed))
+ (should (string= "l1 l3" (org-entry-get marker "LINEAR-LABEL-IDS-SYNCED")))))))
+
;;; --save-description-field (advances both provenance hashes)
(ert-deftest test-pearl-save-description-advances-both-hashes ()