diff options
author | Johnson Denen <johnson.denen@gmail.com> | 2017-04-11 12:55:32 -0400 |
---|---|---|
committer | Johnson Denen <johnson.denen@gmail.com> | 2017-04-12 18:11:48 -0400 |
commit | 9831a8fdae04a4b23b4f4d271d5806131c90a528 (patch) | |
tree | 38e1d477adfb4d99d416e59c7894586df1df5900 | |
parent | d21fdb8b65dbe6bc85f6f28249355a4eeb06102d (diff) |
Add mastodon-auth--registration-success test
-rw-r--r-- | lisp/mastodon-auth.el | 15 | ||||
-rw-r--r-- | test/mastodon-auth-tests.el | 12 |
2 files changed, 21 insertions, 6 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 686e2ae..2d5e19f 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -39,17 +39,20 @@ (defvar mastodon--client-app-plist nil) (defvar mastodon--api-token-string nil) +(defun mastodon-auth--registration-success () + (let ((client-data (mastodon--json-hash-table))) + (setq mastodon--client-app-plist + `(:client_id + ,(gethash "client_id" client-data) + :client_secret + ,(gethash "client_secret" client-data))))) + (defun mastodon--register-client-app-triage (status) "Callback function to triage `mastodon--register-client-app' response. STATUS is passed by `url-retrieve'." (mastodon--http-response-triage status - (lambda () (let ((client-data (mastodon--json-hash-table))) - (setq mastodon--client-app-plist - `(:client_id - ,(gethash "client_id" client-data) - :client_secret - ,(gethash "client_secret" client-data))))))) + 'mastodon-auth--registration-success)) (defun mastodon--register-client-app () "Add `:client_id' and `client_secret' to `mastodon--client-plist'." diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el new file mode 100644 index 0000000..0963e95 --- /dev/null +++ b/test/mastodon-auth-tests.el @@ -0,0 +1,12 @@ +(require 'el-mock) +(load-file "../lisp/mastodon-auth.el") + +(ert-deftest mastodon-auth:registration-success () + (let ((hash (make-hash-table :test 'equal)) + (client-plist '(:client_id "client-id" :client_secret "client-secret"))) + (puthash "client_id" "client-id" hash) + (puthash "client_secret" "client-secret" hash) + (with-mock + (stub mastodon--json-hash-table => hash) + (mastodon-auth--registration-success) + (should (equal client-plist mastodon--client-app-plist))))) |