diff --git a/src/interface/emacs/tests/khoj-tests.el b/src/interface/emacs/tests/khoj-tests.el index 8242d30b..c0d9f4a6 100644 --- a/src/interface/emacs/tests/khoj-tests.el +++ b/src/interface/emacs/tests/khoj-tests.el @@ -206,6 +206,64 @@ Rule everything\n") "Rule everything")) )) + +;; ------------------------------------- +;; Test Helpers to Index Content +;; ------------------------------------- + +(ert-deftest khoj-tests--render-files-to-add-request-body () + "Test files are formatted into a multi-part http request body" + (let ((upgrade-file (make-temp-file "upgrade" nil ".org" "# Become God\n## Upgrade\n\nPenance to Immortality\n\n")) + (act-file (make-temp-file "act" nil ".org" "## Act\n\nRule everything\n\n"))) + (unwind-protect + (progn + (should + (equal + (khoj--render-files-as-request-body (list upgrade-file act-file) '() "khoj") + (format + "\n--khoj\r\n\ +Content-Disposition: form-data; name=\"files\"; filename=\"%s\"\r\n\ +Content-Type: text/org\r\n\r\n\ +# Become God\n\ +## Upgrade\n\n\ +Penance to Immortality\n\n\r +--khoj\r\n\ +Content-Disposition: form-data; name=\"files\"; filename=\"%s\"\r\n\ +Content-Type: text/org\r\n\r\n\ +## Act\n\n\ +Rule everything\n\n\r\n\ +--khoj--\r\n" upgrade-file act-file)))) + (delete-file upgrade-file) + (delete-file act-file)))) + +(ert-deftest khoj-tests--render-files-to-add-delete-in-request-body () + "Test files are formatted into a multi-part http request body" + (let ((upgrade-file (make-temp-file "upgrade" nil ".org" "# Become God\n## Upgrade\n\nPenance to Immortality\n\n")) + (act-file (make-temp-file "act" nil ".org" "## Act\n\nRule everything\n\n"))) + (unwind-protect + (progn + (should + (equal + (khoj--render-files-as-request-body (list upgrade-file act-file) (list upgrade-file act-file "/tmp/deleted-file.org") "khoj") + (format + "\n--khoj\r\n\ +Content-Disposition: form-data; name=\"files\"; filename=\"%s\"\r\n\ +Content-Type: text/org\r\n\r\n\ +# Become God\n\ +## Upgrade\n\n\ +Penance to Immortality\n\n\r +--khoj\r\n\ +Content-Disposition: form-data; name=\"files\"; filename=\"%s\"\r\n\ +Content-Type: text/org\r\n\r\n\ +## Act\n\n\ +Rule everything\n\n\r +--khoj\r\n\ +Content-Disposition: form-data; name=\"files\"; filename=\"%s\"\r\n\ +Content-Type: text/org\r\n\r\n\ +\r +--khoj--\r\n" upgrade-file act-file "/tmp/deleted-file.org")))) + (delete-file upgrade-file) + (delete-file act-file)))) (provide 'khoj-tests)