Browse Source

Fix account merging

* elbank-boobank.el: Detect new accounts by comparing ids.
* test/elbank-boobank-test.el: Add a regression test.
custom-labels 1.1
Nicolas Petton 3 years ago
parent
commit
245cbc218e
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
2 changed files with 18 additions and 7 deletions
  1. +4
    -1
      elbank-boobank.el
  2. +14
    -6
      test/elbank-boobank-test.el

+ 4
- 1
elbank-boobank.el View File

@ -125,7 +125,10 @@ NEW."
new-acc)))
new)
(let ((new-accounts (seq-remove (lambda (acc)
(seq-contains old acc))
(seq-find (lambda (old-acc)
(string= (map-elt old-acc 'id)
(map-elt acc 'id)))
old))
new)))
(seq-concatenate 'list old new-accounts)))


+ 14
- 6
test/elbank-boobank-test.el View File

@ -47,19 +47,27 @@
:to-equal '("1" "2" "3" "4" "5"))))
(it "should keep existing accounts when merging accounts"
(let* ((old '(((id . 1))
((id . 2))))
(new '(((id . 1))
((id . 3))))
(let* ((old '(((id . "1"))
((id . "2"))))
(new '(((id . "1"))
((id . "3"))))
(merged (elbank--merge-accounts old new)))
(message "%s" merged)
(expect (seq-length merged) :to-be 3)
(expect (car merged) :to-be (car old))
(expect (cadr merged) :to-be (cadr old))
(expect (cl-caddr merged) :to-be (cadr new))))
(it "should not duplicate accounts when merging"
(let* ((old '(((id . "1") (label "old"))))
(new '(((id . "1") (label "new"))))
(merged (elbank--merge-accounts old new)))
(expect (seq-length merged) :to-be 1)
(expect (car merged) :to-be (car old))))
(it "merging accounts should update current accounts values"
(let* ((old '(((id . 1) (balance . "3000"))))
(new '(((id . 1) (balance . "3500"))))
(let* ((old '(((id . "1") (balance . "3000"))))
(new '(((id . "1") (balance . "3500"))))
(merged (elbank--merge-accounts old new)))
(expect (seq-length merged) :to-be 1)
(expect (map-elt (car merged) 'balance) :to-equal "3500")))


Loading…
Cancel
Save