aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--lisp/mastodon-auth.el8
-rw-r--r--test/mastodon-auth-tests.el24
3 files changed, 31 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 602f998..45b434e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
# Other
.DS_Store
+stubfile.plstore
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index 1892518..bc09403 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -39,6 +39,10 @@
(defvar mastodon--client-app-plist nil)
(defvar mastodon--api-token-string nil)
+(defun mastodon-auth--token-file ()
+ "Returns `mastodon-token-file' string."
+ mastodon-token-file)
+
(defun mastodon-auth--registration-success ()
(let ((client-data (mastodon--json-hash-table)))
(setq mastodon--client-app-plist
@@ -70,7 +74,7 @@ STATUS is passed by `url-retrieve'."
(defun mastodon--store-client-id-and-secret ()
"Store `:client_id' and `:client_secret' in a plstore."
(let ((client-plist (mastodon--register-and-return-client-app))
- (plstore (plstore-open mastodon-token-file)))
+ (plstore (plstore-open (mastodon-auth--token-file))))
(plstore-put plstore "mastodon" `(:client_id
,(plist-get client-plist :client_id)
:client_secret
@@ -86,7 +90,7 @@ If not set, retrieves client data from `mastodon-token-file'.
If no data can be found in the token file, registers the app and stores its data via `mastodon--store-client-id-and-secret'."
(if (plist-get mastodon--client-app-plist :client_secret)
mastodon--client-app-plist
- (let* ((plstore (plstore-open mastodon-token-file))
+ (let* ((plstore (plstore-open (mastodon-auth--token-file)))
(mastodon (plstore-get plstore "mastodon")))
(if mastodon
(progn
diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el
index 371abcc..0012e3e 100644
--- a/test/mastodon-auth-tests.el
+++ b/test/mastodon-auth-tests.el
@@ -1,6 +1,13 @@
(require 'el-mock)
+
+(load-file "../lisp/mastodon.el")
+(load-file "../lisp/mastodon-http.el")
(load-file "../lisp/mastodon-auth.el")
+(ert-deftest mastodon-auth:token-file ()
+ "Should return `mastodon-token-file' value."
+ (should (string= (mastodon-auth--token-file) "~/.emacs.d/mastodon.plstore")))
+
(ert-deftest mastodon-auth:registration-success ()
"Should set `mastodon--client-app-plist' on succesful registration."
(let ((hash (make-hash-table :test 'equal))
@@ -42,3 +49,20 @@
(with-mock
(mock (mastodon--register-client-app) => app-plist)
(should (equal app-plist (mastodon--register-and-return-client-app))))))
+
+(defun helper:read-plstore (file key)
+ (let* ((plstore (plstore-open file))
+ (masto (delete "mastodon" (plstore-get plstore "mastodon"))))
+ (progn
+ (plstore-close plstore)
+ (plist-get masto key))))
+
+(ert-deftest mastodon-auth:store-client-id-and-secret ()
+ "Should create plstore from client plist. Should return plist."
+ (let ((app-plist '(:client_id "id-val" :client_secret "secret-val")))
+ (with-mock
+ (mock (mastodon--register-and-return-client-app) => app-plist)
+ (mock (mastodon-auth--token-file) => "stubfile.plstore")
+ (should (eq app-plist (mastodon--store-client-id-and-secret)))
+ (should (string= (helper:read-plstore (mastodon-auth--token-file) :client_id) "id-val"))
+ (should (string= (helper:read-plstore (mastodon-auth--token-file) :client_secret) "secret-val")))))