Skip to content

Commit

Permalink
Fix tests caused by triples getting more strict with schema (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyatt authored Sep 1, 2024
1 parent fb87da8 commit f8e2f77
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
122 changes: 62 additions & 60 deletions ekg-denote-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,102 +35,102 @@
(ert-deftest ekg-denote-test-notes-having-duplicate-creation-time ()
"Notes with duplicate creation time should error."
(let* ((time (time-convert (current-time) 'integer))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2" :creation-time time))
(notes (list note1 note2)))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2" :creation-time time))
(notes (list note1 note2)))
(should-error (ekg-denote-assert-notes-have-unique-creation-time notes))))

(ert-deftest ekg-denote-test-notes-having-unique-creation-tiem ()
"Notes with unique creation time should not error."
(let* ((time (time-convert (current-time) 'integer))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2" :creation-time (1+ time)))
(notes (list note1 note2)))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2" :creation-time (1+ time)))
(notes (list note1 note2)))
(should-not (ekg-denote-assert-notes-have-unique-creation-time notes))))

(ert-deftest ekg-denote-test-notes-missing-creation-time ()
"Notes missing creation time should error."
(let* ((time (time-convert (current-time) 'integer))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2")))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2")))
(should-error (ekg-denote-assert-notes-have-creation-time notes))))

(ert-deftest ekg-denote-test-notes-not-missing-creation-time ()
"Notes having creation time should not error."
(let* ((time (time-convert (current-time) 'integer))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2" :creation-time (1+ time)))
(notes (list note1 note2)))
(note1 (make-ekg-note :id "ID1" :creation-time time))
(note2 (make-ekg-note :id "ID2" :creation-time (1+ time)))
(notes (list note1 note2)))
(should-not (ekg-denote-assert-notes-have-creation-time notes))))

(ert-deftest ekg-denote-test-create ()
"Verify creation of `ekg-denote' against given ekg note."

; date tag is removed.
; text defaults to ""
; ext defaults to ekg-default-capture-mode
; title defaults to ""
; path uses denote-id and tags
; ekg-id is copied
; date tag is removed.
; text defaults to ""
; ext defaults to ekg-default-capture-mode
; title defaults to ""
; path uses denote-id and tags
; ekg-id is copied
(let* ((time (time-convert (current-time) 'integer))
(denote-directory "/tmp")
(denote-id (format-time-string denote-id-format time))
(ekg-default-capture-mode 'org-mode)
(note (make-ekg-note :id "ID1"
:creation-time time
:tags '("date/20230101" "portfolio" "tag2")))
(denote (make-ekg-denote :id denote-id
:note-id "ID1"
:title ""
:text ""
:path (format "/tmp/%s__portfolio_tag2.org" denote-id )
:kws '("portfolio" "tag2"))))
(denote-directory "/tmp")
(denote-id (format-time-string denote-id-format time))
(ekg-default-capture-mode 'org-mode)
(note (make-ekg-note :id "ID1"
:creation-time time
:tags '("date/20230101" "portfolio" "tag2")))
(denote (make-ekg-denote :id denote-id
:note-id "ID1"
:title ""
:text ""
:path (format "/tmp/%s__portfolio_tag2.org" denote-id )
:kws '("portfolio" "tag2"))))
(should (equal denote (ekg-denote-create note))))

;; scalar title values shall work
(let* ((time (time-convert (current-time) 'integer))
(denote-directory "/tmp")
(denote-id (format-time-string denote-id-format time))
(ekg-default-capture-mode 'org-mode)
(note (make-ekg-note :id "ID1"
:creation-time time
:text "Text"
:properties `(:titled/title "MyTitle")
:tags '("date/20230101" "portfolio")))
(denote (make-ekg-denote :id denote-id
:note-id "ID1"
:title "mytitle"
:text "Text"
:path (format "/tmp/%s--mytitle__portfolio.org" denote-id )
:kws '("portfolio"))))
(denote-directory "/tmp")
(denote-id (format-time-string denote-id-format time))
(ekg-default-capture-mode 'org-mode)
(note (make-ekg-note :id "ID1"
:creation-time time
:text "Text"
:properties `(:titled/title "MyTitle")
:tags '("date/20230101" "portfolio")))
(denote (make-ekg-denote :id denote-id
:note-id "ID1"
:title "mytitle"
:text "Text"
:path (format "/tmp/%s--mytitle__portfolio.org" denote-id )
:kws '("portfolio"))))
(should (equal denote (ekg-denote-create note))))

;; text is copied as it is
;; title is truncated, copied and sluggified
(let* ((time (time-convert (current-time) 'integer))
(denote-directory "/tmp")
(denote-id (format-time-string denote-id-format time))
(ekg-default-capture-mode 'org-mode)
(ekg-denote-export-title-max-len 10)
(note (make-ekg-note :id "ID1"
:creation-time time
:text "Text"
:properties `(:titled/title ,(list "Title 123456789"))
:tags '("date/20230101" "portfolio")))
(denote (make-ekg-denote :id denote-id
:note-id "ID1"
:title "title-1234"
:text "Text"
:path (format "/tmp/%s--title-1234__portfolio.org" denote-id )
:kws '("portfolio"))))
(denote-directory "/tmp")
(denote-id (format-time-string denote-id-format time))
(ekg-default-capture-mode 'org-mode)
(ekg-denote-export-title-max-len 10)
(note (make-ekg-note :id "ID1"
:creation-time time
:text "Text"
:properties `(:titled/title ,(list "Title 123456789"))
:tags '("date/20230101" "portfolio")))
(denote (make-ekg-denote :id denote-id
:note-id "ID1"
:title "title-1234"
:text "Text"
:path (format "/tmp/%s--title-1234__portfolio.org" denote-id )
:kws '("portfolio"))))
(should (equal denote (ekg-denote-create note)))))


(defun ekg-test--matching-denote (regexp)
"Get denote file name containing REGEXP.
Enforces single match."
(let ((files (seq-filter (lambda (x) (string-match-p regexp x))
(denote-directory-files nil nil :text-only))))
(denote-directory-files nil nil :text-only))))
(when files (car files))))

(defun ekg-test--denote-text (file)
Expand All @@ -150,12 +150,13 @@ Enforces single match."
(defun ekg-test--denote-ekg (file)
"Return ekg note for given denote FILE."
(let* ((creation-time (ekg-test--creation-time-from-denote-file file))
(triples (triples-db-select-pred-op ekg-db :time-tracked/creation-time '= creation-time)))
(triples (triples-db-select-pred-op ekg-db :time-tracked/creation-time '= creation-time)))
(should (length= triples 1))
(ekg-get-note-with-id (car (car triples)))))

(ekg-deftest ekg-denote-test-export ()
"Verify export."
(ekg-denote-add-schema)
(let ((denote-directory (make-temp-file "denote" t)))
;; ekg note creations are exported
(ekg-save-note (ekg-note-create :text "text1" :mode 'org-mode :tags '("portfolio")))
Expand All @@ -182,6 +183,7 @@ Enforces single match."

(ekg-deftest ekg-denote-test-last-export ()
"Verify last export time updates."
(ekg-denote-add-schema)
(should (= 0 (ekg-denote-get-last-export)))
(ekg-denote-set-last-export 123)
(should (= 123 (ekg-denote-get-last-export))))
2 changes: 2 additions & 0 deletions ekg-logseq-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
(should (equal "foo/bar" (ekg-logseq-filename-to-tag "foo$bar.org"))))

(ekg-deftest ekg-logseq-test-last-import-export ()
(ekg-logseq-add-schema)
(should (= 0 (ekg-logseq-get-last-export)))
(should (= 0 (ekg-logseq-get-last-import)))
(ekg-logseq-set-last-export 123)
Expand All @@ -169,6 +170,7 @@
(should (= 456 (ekg-logseq-get-last-import))))

(ekg-deftest ekg-logseq-test-tags-with-notes-modified-since ()
(ekg-logseq-add-schema)
(cl-flet ((create (time tags)
(let ((note (ekg-note-create :text "" :mode 'org-mode :tags tags)))
(cl-letf (((symbol-function 'time-convert)
Expand Down

0 comments on commit f8e2f77

Please sign in to comment.