|
482 | 482 | result |
483 | 483 | nil)] |
484 | 484 | (is (= (:details result) details))))) |
| 485 | + |
| 486 | +(deftest auto-clear-completed-test |
| 487 | + (testing "clears task list when all tasks are done" |
| 488 | + (let [db* (atom {:chats {"c1" {:task {:next-id 3 |
| 489 | + :active-summary nil |
| 490 | + :tasks [{:id 1 :subject "T1" :description "D1" :status :done :priority :medium :blocked-by #{}} |
| 491 | + {:id 2 :subject "T2" :description "D2" :status :done :priority :medium :blocked-by #{}}]}}}}) |
| 492 | + result (task/auto-clear-completed! db* "c1")] |
| 493 | + (is (some? result)) |
| 494 | + (is (= :task (:type result))) |
| 495 | + (is (empty? (:tasks result))) |
| 496 | + (is (= {:next-id 1 :active-summary nil :tasks []} |
| 497 | + (task/get-task @db* "c1"))))) |
| 498 | + |
| 499 | + (testing "does not clear when tasks are still pending" |
| 500 | + (let [db* (atom {:chats {"c1" {:task {:next-id 3 |
| 501 | + :active-summary nil |
| 502 | + :tasks [{:id 1 :subject "T1" :description "D1" :status :done :priority :medium :blocked-by #{}} |
| 503 | + {:id 2 :subject "T2" :description "D2" :status :pending :priority :medium :blocked-by #{}}]}}}}) |
| 504 | + result (task/auto-clear-completed! db* "c1")] |
| 505 | + (is (nil? result)) |
| 506 | + (is (= 2 (count (:tasks (task/get-task @db* "c1"))))))) |
| 507 | + |
| 508 | + (testing "does not clear when tasks are in progress" |
| 509 | + (let [db* (atom {:chats {"c1" {:task {:next-id 3 |
| 510 | + :active-summary "working" |
| 511 | + :tasks [{:id 1 :subject "T1" :description "D1" :status :done :priority :medium :blocked-by #{}} |
| 512 | + {:id 2 :subject "T2" :description "D2" :status :in-progress :priority :medium :blocked-by #{}}]}}}}) |
| 513 | + result (task/auto-clear-completed! db* "c1")] |
| 514 | + (is (nil? result)) |
| 515 | + (is (= 2 (count (:tasks (task/get-task @db* "c1"))))))) |
| 516 | + |
| 517 | + (testing "does nothing when task list is empty" |
| 518 | + (let [db* (atom {:chats {"c1" {:task {:next-id 1 :active-summary nil :tasks []}}}}) |
| 519 | + result (task/auto-clear-completed! db* "c1")] |
| 520 | + (is (nil? result)) |
| 521 | + (is (= {:next-id 1 :active-summary nil :tasks []} |
| 522 | + (task/get-task @db* "c1"))))) |
| 523 | + |
| 524 | + (testing "does nothing when chat has no task list" |
| 525 | + (let [db* (atom {}) |
| 526 | + result (task/auto-clear-completed! db* "c1")] |
| 527 | + (is (nil? result)) |
| 528 | + (is (= {:next-id 1 :active-summary nil :tasks []} |
| 529 | + (task/get-task @db* "c1")))))) |
0 commit comments