diff options
author | Johnson Denen <johnson.denen@gmail.com> | 2017-04-12 13:55:23 -0400 |
---|---|---|
committer | Johnson Denen <johnson.denen@gmail.com> | 2017-04-12 18:11:48 -0400 |
commit | e20f074de9927451a8f3f496632a39e4937b78b8 (patch) | |
tree | 87c93cae7ca7013cbcfc8fcb2bd379b00797206f | |
parent | 525235938369dd035c3e2bd073186266c7815af9 (diff) |
Add tests for `mastodon--access-token'
-rw-r--r-- | lisp/mastodon-auth.el | 19 | ||||
-rw-r--r-- | test/mastodon-auth-tests.el | 16 |
2 files changed, 26 insertions, 9 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 1f4adaf..a35dc5a 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -135,18 +135,21 @@ Authenticates with email address and password. Neither are not stored." ("password" . ,passwd) ("scope" . "read write follow"))))) +(defun mastodon-auth--token () + "Return `mastodon--api-token-string'." + mastodon--api-token-string) + (defun mastodon--access-token () "Return `mastodon--api-token-string'. If not set, retrieves token with `mastodon--get-access-token'." - (if mastodon--api-token-string - mastodon--api-token-string - (progn - (mastodon--get-access-token) - (while (not mastodon--api-token-string) - (sleep-for 1) - (mastodon--access-token)) - mastodon--api-token-string))) + (or (mastodon-auth--token) + (progn + (mastodon--get-access-token) + (or (mastodon-auth--token) + (progn + (sleep-for 2) + (mastodon--access-token)))))) (provide 'mastodon-auth) ;;; mastodon-auth.el ends here diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 6e8b10c..7c2bb0c 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -103,7 +103,7 @@ (mastodon--get-access-token-triage "status"))) (ert-deftest mastodon-auth:get-access-token () - "Should POST auth data to retreive access token." + "Should POST auth data to retrieve access token." (let ((client-app '(:client_id "id" :client_secret "secret"))) (with-mock (mock (mastodon-auth--user-and-passwd) => (cons "email" "password")) @@ -117,3 +117,17 @@ ("password" . "password") ("scope" . "read write follow")))) (mastodon--get-access-token)))) + +(ert-deftest mastodon-auth:access-token:memoized () + "Should return `mastodon--api-token-string' if set." + (with-mock + (mock (mastodon-auth--token) => "foobar") + (should (string= (mastodon--access-token) "foobar")))) + +(ert-deftest mastodon-auth:access-token:generated () + "Should generate `mastodon--api-token-string' if not memoized." + (with-mock + (mock (mastodon-auth--token) => nil) + (mock (mastodon--get-access-token) + => (mock (mastodon-auth--token) => "foobar")) + (should (string= (mastodon--access-token) "foobar")))) |