Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to create dummy data for testing purposes #14

Closed
jgru opened this issue Oct 11, 2022 · 1 comment
Closed

Add function to create dummy data for testing purposes #14

jgru opened this issue Oct 11, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@jgru
Copy link
Owner

jgru commented Oct 11, 2022

As proposed by @apc in the course of the discussion regarding #13, there should be a pre-populated org-roam-directory so that the package could be easily tested. To achieve this, a function should be created and documented in the wiki to make the configuration for testing purposes more complete and comprehensive.

About the test config, have you considered just having some test files that can be downloaded as part of the repo, which could be what org-roam-dir is set to according to your minimal config? I think citar has something like that setup and I think it works fine.

-- @apc

@jgru jgru added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 11, 2022
@jgru
Copy link
Owner Author

jgru commented Dec 11, 2022

Dummy data for testing purposes can now be automatically created using the minimal-setup.el provided in the wiki.
The relevant elisp functions are the following ones:

(setq test-org-roam-directory (make-temp-file "roam-" t))

(with-eval-after-load 'org-roam
  (defun create-org-roam-dummy-note (title body)
    "Create an org-roam note file with TITLE and content BODY."
    (let* ((slug (org-roam-node-slug (org-roam-node-create :title title)))
            (filename (concat (file-name-as-directory org-roam-directory)
                        (format "%d-%s.org"
                          (time-convert (current-time) 'integer)
                          slug)))
            (org-id-overriding-file-name filename)
            id)
      (with-temp-buffer
        filename
        (insert ":PROPERTIES:\n:ID:        \n:END:\n#+title: "
          title)
        (goto-char 25)
        (setq id (org-id-get-create))
        (goto-char (point-max))
        (newline 2)
        (insert body)
        (write-file filename)
        (org-roam-db-update-file filename))))

  (defun populate-org-roam-with-dummy-notes ()
    "Create some test notes in org-roam-directory."
    (let ((elems '("alpha" "bravo" "charlie" "delta" "echo" "foxtrot")))
      ;; Check existence of org-roam-directory
      (when (not (file-directory-p org-roam-directory))
        (make-directory org-roam-directory))
      ;; Create the single notes 
      (dolist (elt elems )
        (create-org-roam-dummy-note elt
          (concat "This is the body of a note about " elt)))))
  (populate-org-roam-with-dummy-notes))

This snippet creates notes in a uniquely named temp-directory by iterating over elems.
The resulting files have the following simplistic structure:

:PROPERTIES:
:ID:       a8b97174-48e6-453d-8f73-8e3cd1d955b0
:END:
#+title: alpha

This is the body of a note about alpha

This can be conveniently used to test consult-org-roam's functionality

@jgru jgru closed this as completed Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant