aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-auth.el9
-rw-r--r--test/mastodon-auth-tests.el8
-rw-r--r--test/mastodon-tl-tests.el20
-rw-r--r--test/mastodon-toot-tests.el20
4 files changed, 19 insertions, 38 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el
index 09813d3..a608dbe 100644
--- a/lisp/mastodon-auth.el
+++ b/lisp/mastodon-auth.el
@@ -36,10 +36,10 @@
:group 'mastodon)
(defvar mastodon-auth--token nil
- "")
+ "User access token.")
(defun mastodon-auth--generate-token ()
- ""
+ "Make POST to generate auth token."
(mastodon-http--post
(concat mastodon-instance-url "/oauth/token")
`(("client_id" . ,(plist-get (mastodon-client) :client_id))
@@ -51,7 +51,7 @@
nil))
(defun mastodon-auth--get-token ()
- ""
+ "Make auth token request and return JSON response."
(with-current-buffer (mastodon-auth--generate-token)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
@@ -62,6 +62,9 @@
(json-read-from-string json-string))))
(defun mastodon-auth--access-token ()
+ "Return `mastodon-auth--token'.
+
+Generate token and set `mastodon-auth--token' if nil."
(or mastodon-auth--token
(progn
(let* ((json (mastodon-auth--get-token))
diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el
index e46f1a6..70c63d8 100644
--- a/test/mastodon-auth-tests.el
+++ b/test/mastodon-auth-tests.el
@@ -1,7 +1,7 @@
(require 'el-mock)
(ert-deftest generate-token ()
- ""
+ "Should make `mastdon-http--post' request to generate auth token."
(with-mock
(let ((mastodon-instance-url "https://instance.url"))
(mock (mastodon-client) => '(:client_id "id" :client_secret "secret"))
@@ -18,7 +18,7 @@
(mastodon-auth--generate-token))))
(ert-deftest get-token ()
- ""
+ "Should generate token and return JSON response."
(with-temp-buffer
(with-mock
(mock (mastodon-auth--generate-token) => (progn
@@ -27,12 +27,12 @@
(should (equal (mastodon-auth--get-token) '(:access_token "abcdefg"))))))
(ert-deftest access-token-1 ()
- ""
+ "Should return `mastodon-auth--token' if non-nil."
(let ((mastodon-auth--token "foobar"))
(should (string= (mastodon-auth--access-token) "foobar"))))
(ert-deftest access-token-2 ()
- ""
+ "Should set and return `mastodon-auth--token' if nil."
(let ((mastodon-auth--token nil))
(with-mock
(mock (mastodon-auth--get-token) => '(:access_token "foobaz"))
diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el
index 19d7e55..9c45abd 100644
--- a/test/mastodon-tl-tests.el
+++ b/test/mastodon-tl-tests.el
@@ -1,15 +1,11 @@
(require 'el-mock)
-(ert-deftest mastodon-tl:from-toot ()
- "Should return the value for KEY in a list."
- (should (string= (mastodon-tl--from-toot "foo" '(("foo" . "bar"))) "bar")))
+(ert-deftest remove-html-1 ()
+ "Should remove all <span> tags."
+ (let ((input "<span class=\"h-card\">foobar</span> <span>foobaz</span>"))
+ (should (string= (mastodon-tl--remove-html input) "foobar foobaz"))))
-(ert-deftest mastodon-tl:remove-html:remove-p-and-span ()
- "Should remove <p> and <span> tags that are not parsed by `html2text'."
- (let ((input "<p>foo<span>bar</span></p>"))
- (should (string= (mastodon-tl--remove-html input) "foobar\n"))))
-
-(ert-deftest mastodon-tl:remove-html:remove-hcard-span ()
- "Should remove <span> tags with a class of 'h-card'."
- (let ((input "<span class=\"h-card\">foobar</span>"))
- (should (string= (mastodon-tl--remove-html input) "foobar"))))
+(ert-deftest remove-html-2 ()
+ "Should replace <\p> tags with two new lines."
+ (let ((input "foobar</p>"))
+ (should (string= (mastodon-tl--remove-html input) "foobar\n\n"))))
diff --git a/test/mastodon-toot-tests.el b/test/mastodon-toot-tests.el
index ca04ae8..e9d3b26 100644
--- a/test/mastodon-toot-tests.el
+++ b/test/mastodon-toot-tests.el
@@ -1,24 +1,6 @@
(require 'el-mock)
-(ert-deftest mastodon-toot:cancel ()
+(ert-deftest cancel ()
(with-mock
(mock (kill-buffer-and-window))
(should (eq nil (mastodon-toot--cancel)))))
-
-(ert-deftest mastodon-toot:send ()
- (with-mock
- (stub mastodon--api-for => "https://instance/api/v/statuses")
- (stub buffer-string => "This is a test toot")
- (stub kill-buffer-and-window)
- (stub mastodon-auth--access-token => "access-token-string")
- (mock (mastodon--http-post "https://instance/api/v/statuses"
- 'mastodon-toot--send-triage
- '(("status" . "This is a test toot"))
- '(("Authorization" . "Bearer access-token-string"))))
- (should (eq nil (mastodon-toot--send)))))
-
-(ert-deftest mastodon-toot:send-triage ()
- (with-mock
- (mock (mastodon--http-response-triage "status"
- (lambda () (switch-to-buffer (current-buffer)))))
- (should (eq nil (mastodon-toot--send-triage "status")))))