Browse Source

Fix merging new transaction (Fix #1)

* elbank-boobank.el (elbank--new-transaction): When merging new data, only
  deduplicate new transactions before importing them.
* Cask:
* run-tests.sh: Add buttercup to the test suites.
* test/elbank-boobank-test.el: Add regression tests for #1.
* test/elbank-test.el: Delete empty file.
master
Nicolas Petton 2 years ago
parent
commit
dc0239873d
Signed by untrusted user: nico GPG Key ID: 233587A47C207910
5 changed files with 93 additions and 40 deletions
  1. +1
    -0
      Cask
  2. +10
    -4
      elbank-boobank.el
  3. +1
    -0
      run-tests.sh
  4. +81
    -0
      test/elbank-boobank-test.el
  5. +0
    -36
      test/elbank-test.el

+ 1
- 0
Cask View File

@@ -5,6 +5,7 @@
(development
(depends-on "ecukes")
(depends-on "espuds")
(depends-on "buttercup")
(depends-on "flycheck")
(depends-on "flycheck-cask")
(depends-on "f")


+ 10
- 4
elbank-boobank.el View File

@@ -110,10 +110,16 @@ OLD and NEW are lists of transactions for the same account."

(defun elbank--new-transactions (old new)
"Return all transactions not present in OLD bu present in NEW."
(seq-filter (lambda (trans)
(> (seq-count (lambda (elt) (equal elt trans)) new)
(seq-count (lambda (elt) (equal elt trans)) old)))
new))
(apply #'seq-concatenate 'list
(seq-map (lambda (trans)
(let ((n (- (seq-count (lambda (elt) (equal elt trans)) new)
(seq-count (lambda (elt) (equal elt trans)) old))))
(when (> n 0)
(let ((result))
(dotimes (_ n)
(setq result (cons trans result)))
result))))
(seq-uniq new))))

(defun elbank--find-boobank-executable ()
"Return the boobank executable.


+ 1
- 0
run-tests.sh View File

@@ -1,2 +1,3 @@
#!/bin/sh -e
cask exec ecukes "$@"
cask exec buttercup -l features/support/test-helper.el -L . "$@"

+ 81
- 0
test/elbank-boobank-test.el View File

@@ -0,0 +1,81 @@
;;; elbank-boobank-test.el --- Tests for elbank-boobank.el

;; Copyright (C) 2017 Nicolas Petton

;; Author: Nicolas Petton <nicolas@petton.fr>

;; This file is not part of GNU Emacs.

;; 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 elbank-boobank.el

;;; Code:

(require 'buttercup)
(require 'map)
(require 'elbank-boobank)

(describe "Merging data"
(it "should keep new accounts"
(let* ((old '((accounts . [((id . "account1"))
((id . "account2"))])))
(new '((accounts . [((id . "account1"))
((id . "account3"))])))
(merged (elbank--merge-data old new)))
(expect (map-elt merged 'accounts) :to-equal
[((id . "account1"))
((id . "account3"))])))

(it "should append new transactions and keep old ones"
(let* ((old `((accounts . [((id . "account1") (label . "account 1"))])
(transactions (account1 . [((label "1"))
((label "2"))
((label "3"))]))))
(new `((accounts . [((id . "account1") (label . "account 1"))])
(transactions (account1 . [((label "4"))
((label "5"))]))))
(merged (elbank--merge-data old new)))
(expect (map-elt merged 'transactions) :to-equal
'((account1 . [((label "1"))
((label "2"))
((label "3"))
((label "4"))
((label "5"))])))))

(it "should deduplicate new transactions"
(let* ((old `((accounts . [((id . "account1") (label . "account 1"))])
(transactions (account1 . [((label "1"))
((label "2"))
((label "3"))
((label "3"))]))))
(new `((accounts . [((id . "account1") (label . "account 1"))])
(transactions (account1 . [((label "2"))
((label "3"))
((label "3"))
((label "3"))
((label "3"))]))))
(merged (elbank--merge-data old new)))
(expect (map-elt merged 'transactions) :to-equal
'((account1 . [((label "1"))
((label "2"))
((label "3"))
((label "3"))
((label "3"))
((label "3"))]))))))

(provide 'elbank-boobank-test)
;;; elbank-boobank-test.el ends here

+ 0
- 36
test/elbank-test.el View File

@@ -1,36 +0,0 @@
;;; elbank-test.el --- Tests for elbank.el

;; Copyright (C) 2013 Nicolas Petton

;; Author: Nicolas Petton <nicolas@petton.fr>

;; This file is not part of GNU Emacs.

;; 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 elbank.el

;;; Code:

(require 'ert)
(require 'elbank)

(ert-deftest elbank-check-sum ()
(should (equal (+ 1 1) 2)))

(provide 'elbank-test)

;;; elbank-test.el ends here

Loading…
Cancel
Save