aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnson Denen <johnson.denen@gmail.com>2017-04-12 12:04:03 -0400
committerJohnson Denen <johnson.denen@gmail.com>2017-04-12 18:11:48 -0400
commit40a54819cfcba889a812c721d4cc0743ce5ae544 (patch)
treea390a82f76b73711c0e70c00da041e3d31f0fb92
parent59390fba8c795973069064f4216550f4e088a98f (diff)
Abstract success lambda to its own function and test
Add `mastodon-auth--get-token-success' Add test for `mastodon-auth--get-token-success' Add test for `mastodon--get-access-token-triage'
-rw-r--r--lisp/mastodon-auth.el12
-rw-r--r--test/mastodon-auth-tests.el14
2 files changed, 21 insertions, 5 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index bc09403..9ded694 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -100,16 +100,18 @@ If no data can be found in the token file, registers the app and stores its data
(setq mastodon--client-app-plist (mastodon--store-client-id-and-secret))
mastodon--client-app-plist)))))
+(defun mastodon-auth--get-token-success ()
+ (let ((token-data (mastodon--json-hash-table)))
+ (progn
+ (setq mastodon--api-token-string (gethash "access_token" token-data))
+ mastodon--api-token-string)))
+
(defun mastodon--get-access-token-triage (status)
"Callback function to triage `mastodon--get-access-token' response.
STATUS is passed by `url-retrieve'."
(mastodon--http-response-triage status
- (lambda ()
- (let ((token-data (mastodon--json-hash-table)))
- (progn
- (setq mastodon--api-token-string (gethash "access_token" token-data))
- mastodon--api-token-string)))))
+ 'mastodon-auth--get-token-success))
(defun mastodon--get-access-token ()
"Retrieve access token from instance.
diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el
index 95ba597..4560e27 100644
--- a/test/mastodon-auth-tests.el
+++ b/test/mastodon-auth-tests.el
@@ -87,3 +87,17 @@
(mock (mastodon-auth--token-file) => "fixture/empty.plstore")
(mock (mastodon--store-client-id-and-secret))
(mastodon--client-app)))
+
+(ert-deftest mastodon-auth:get-token-success ()
+ "Should return access token from `url-retrieve' response JSON."
+ (let ((hash (make-hash-table :test 'equal)))
+ (puthash "access_token" "token-value" hash)
+ (with-mock
+ (mock (mastodon--json-hash-table) => hash)
+ (should (string= (mastodon-auth--get-token-success) "token-value")))))
+
+(ert-deftest mastodon-auth:get-access-token-triage ()
+ "Should wrap `mastodon--http-response-triage'."
+ (with-mock
+ (mock (mastodon--http-response-triage "status" 'mastodon-auth--get-token-success))
+ (mastodon--get-access-token-triage "status")))