diff options
author | marty hiatt <martianhiatus@riseup.net> | 2023-10-30 19:54:12 +0100 |
---|---|---|
committer | marty hiatt <martianhiatus@riseup.net> | 2023-10-30 19:54:12 +0100 |
commit | cf7b3710c682cbad444016ab7f9b9639cef84453 (patch) | |
tree | fd482f96947d5d1c530129546a83394a8866a971 /test | |
parent | d8bd51da807633a3a55923fe00aa0eb1141a3df1 (diff) | |
parent | 40e8123b84ce54100a818e6b19507d3a492614f6 (diff) |
Merge branch 'develop'
Diffstat (limited to 'test')
-rw-r--r-- | test/mastodon-http-tests.el | 6 | ||||
-rw-r--r-- | test/mastodon-profile-tests.el | 4 | ||||
-rw-r--r-- | test/mastodon-tl-tests.el | 174 | ||||
-rw-r--r-- | test/mastodon-toot-tests.el | 12 |
4 files changed, 103 insertions, 93 deletions
diff --git a/test/mastodon-http-tests.el b/test/mastodon-http-tests.el index b3a02bc..96f9304 100644 --- a/test/mastodon-http-tests.el +++ b/test/mastodon-http-tests.el @@ -62,11 +62,11 @@ Strict-Transport-Security: max-age=31536000 (let ((response-buffer (get-buffer-create "mastodon-http--triage-buffer"))) (with-current-buffer response-buffer - (erase-buffer) + (erase-buffer) (insert mastodon-http--example-200)) (should (equal (mastodon-http--triage response-buffer - (lambda () + (lambda (_) (message "success call"))) "success call")))) @@ -80,7 +80,7 @@ Strict-Transport-Security: max-age=31536000 (insert mastodon-http--example-400)) (should (equal (mastodon-http--triage response-buffer - (lambda () + (lambda (_) (message "success call"))) "Error 444: some unhappy complaint")))) diff --git a/test/mastodon-profile-tests.el b/test/mastodon-profile-tests.el index 1936b99..d187e2d 100644 --- a/test/mastodon-profile-tests.el +++ b/test/mastodon-profile-tests.el @@ -158,11 +158,11 @@ When formatting Gargon's state we want to see t)) (should (equal - (get-text-property 4 'toot-id) + (get-text-property 4 'item-id) (alist-get 'id gargron-profile-json))) (should (equal - (get-text-property 4 'toot-json) + (get-text-property 4 'item-json) gargron-profile-json))))) (ert-deftest mastodon-profile--search-account-by-handle--removes-at () diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index d6940d4..2aa0505 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -168,16 +168,16 @@ Strict-Transport-Security: max-age=31536000 (let ((input "foobar</p>")) (should (string= (mastodon-tl--remove-html input) "foobar\n\n")))) -(ert-deftest mastodon-tl--toot-id-boosted () +(ert-deftest mastodon-tl--item-id-boosted () "If a toot is boostedm, return the reblog id." (should (string= (mastodon-tl--as-string - (mastodon-tl--toot-id mastodon-tl-test-base-boosted-toot)) + (mastodon-tl--item-id mastodon-tl-test-base-boosted-toot)) "4543919"))) -(ert-deftest mastodon-tl--toot-id () +(ert-deftest mastodon-tl--item-id () "If a toot is boostedm, return the reblog id." (should (string= (mastodon-tl--as-string - (mastodon-tl--toot-id mastodon-tl-test-base-toot)) + (mastodon-tl--item-id mastodon-tl-test-base-toot)) "61208"))) (ert-deftest mastodon-tl--as-string-1 () @@ -849,12 +849,10 @@ Strict-Transport-Security: max-age=31536000 (should (equal (list 'next test-name expected-next) (list 'next test-name (point))))))))))) - (defun tl-tests--property-values-at (property ranges) "Returns a list with property values at the given ranges. - - The property value for PROPERTY within a region is assumed to be - constant." +The property value for PROPERTY within a region is assumed to be +constant." (let (result) (dolist (range ranges (nreverse result)) (push (get-text-property (car range) property) result)))) @@ -928,19 +926,19 @@ Strict-Transport-Security: max-age=31536000 (insert "some text before\n") (setq toot-start (point)) (with-mock - (mock (mastodon-profile--get-preferences-pref - 'reading:expand:spoilers) - => :json-false) - (stub create-image => '(image "fake data")) - (stub shr-render-region => nil) ;; Travis's Emacs doesn't have libxml - (insert - (mastodon-tl--spoiler normal-toot-with-spoiler))) + (mock (mastodon-profile--get-preferences-pref + 'reading:expand:spoilers) + => :json-false) + (stub create-image => '(image "fake data")) + (stub shr-render-region => nil) ;; Travis's Emacs doesn't have libxml + (insert + (mastodon-tl--spoiler normal-toot-with-spoiler))) (setq toot-end (point)) (insert "\nsome more text.") (add-text-properties toot-start toot-end - (list 'toot-json normal-toot-with-spoiler - 'toot-id (cdr (assoc 'id normal-toot-with-spoiler)))) + (list 'item-json normal-toot-with-spoiler + 'item-id (cdr (assoc 'id normal-toot-with-spoiler)))) (goto-char toot-start) ;; (should (eq t (looking-at "This is the spoiler warning text"))) @@ -1092,56 +1090,68 @@ correct value for following, as well as notifications enabled or disabled." (let ((response-buffer-true (current-buffer))) (insert mastodon-tl--follow-notify-true-response) (with-mock - (mock (mastodon-http--post url-follow-only nil) - => response-buffer-true) - (should - (equal - (mastodon-tl--do-user-action-function url-follow-only - user-name - user-handle - "follow") - "User some-user (@some-user@instance.url) followed!")) - (mock (mastodon-http--post url-mute nil) - => response-buffer-true) - (should - (equal - (mastodon-tl--do-user-action-function url-mute - user-name - user-handle - "mute") - "User some-user (@some-user@instance.url) muted!")) - (mock (mastodon-http--post url-block nil) - => response-buffer-true) - (should - (equal - (mastodon-tl--do-user-action-function url-block - user-name - user-handle - "block") - "User some-user (@some-user@instance.url) blocked!"))) + (mock (mastodon-http--post url-follow-only nil) + => response-buffer-true) + (should + (equal + (mastodon-tl--do-user-action-function url-follow-only + user-name + user-handle + "follow") + "User some-user (@some-user@instance.url) followed!"))))) + (with-temp-buffer + (let ((response-buffer-true (current-buffer))) + (insert mastodon-tl--follow-notify-true-response) + (with-mock + (mock (mastodon-http--post url-mute nil) + => response-buffer-true) + (should + (equal + (mastodon-tl--do-user-action-function url-mute + user-name + user-handle + "mute") + "User some-user (@some-user@instance.url) muted!"))))) + (with-temp-buffer + (let ((response-buffer-true (current-buffer))) + (insert mastodon-tl--follow-notify-true-response) + (with-mock + (mock (mastodon-http--post url-block nil) + => response-buffer-true) + (should + (equal + (mastodon-tl--do-user-action-function url-block + user-name + user-handle + "block") + "User some-user (@some-user@instance.url) blocked!"))))) + (with-temp-buffer + (let ((response-buffer-true (current-buffer))) + (insert mastodon-tl--follow-notify-true-response) (with-mock - (mock (mastodon-http--post url-true nil) => response-buffer-true) - (should - (equal - (mastodon-tl--do-user-action-function url-true - user-name - user-handle - "follow" - "true") - "Receiving notifications for user some-user (@some-user@instance.url)!"))))) + (with-mock + (mock (mastodon-http--post url-true nil) => response-buffer-true) + (should + (equal + (mastodon-tl--do-user-action-function url-true + user-name + user-handle + "follow" + "true") + "Receiving notifications for user some-user (@some-user@instance.url)!")))))) (with-temp-buffer (let ((response-buffer-false (current-buffer))) (insert mastodon-tl--follow-notify-false-response) (with-mock - (mock (mastodon-http--post url-false nil) => response-buffer-false) - (should - (equal - (mastodon-tl--do-user-action-function url-false - user-name - user-handle - "follow" - "false") - "Not receiving notifications for user some-user (@some-user@instance.url)!"))))))) + (mock (mastodon-http--post url-false nil) => response-buffer-false) + (should + (equal + (mastodon-tl--do-user-action-function url-false + user-name + user-handle + "follow" + "false") + "Not receiving notifications for user some-user (@some-user@instance.url)!"))))))) (ert-deftest mastodon-tl--report-to-mods-params-alist () "" @@ -1149,28 +1159,28 @@ correct value for following, as well as notifications enabled or disabled." (let* ((toot mastodon-tl-test-base-toot) (account (alist-get 'account toot))) (with-mock - ;; no longer needed after our refactor - ;; (mock (mastodon-http--api "reports") => "https://instance.url/api/v1/reports") - ;; (mock (mastodon-tl--toot-or-base - ;; (mastodon-tl--property 'toot-json :no-move)) - ;; => mastodon-tl-test-base-toot) - (mock (read-string "Add comment [optional]: ") => "Dummy complaint") - (stub y-or-n-p => nil) ; no to all + ;; no longer needed after our refactor + ;; (mock (mastodon-http--api "reports") => "https://instance.url/api/v1/reports") + ;; (mock (mastodon-tl--toot-or-base + ;; (mastodon-tl--property 'item-json :no-move)) + ;; => mastodon-tl-test-base-toot) + (mock (read-string "Add comment [optional]: ") => "Dummy complaint") + (stub y-or-n-p => nil) ; no to all + (should (equal (mastodon-tl--report-params account toot) + '(("account_id" . 42) + ("comment" . "Dummy complaint") + ("category" . "other")))) + (with-mock + (stub y-or-n-p => t) ; yes to all + (mock (mastodon-tl--read-rules-ids) => '(1 2 3)) (should (equal (mastodon-tl--report-params account toot) - '(("account_id" . 42) + '(("rule_ids[]" . 3) + ("rule_ids[]" . 2) + ("rule_ids[]" . 1) + ("account_id" . 42) ("comment" . "Dummy complaint") - ("category" . "other")))) - (with-mock - (stub y-or-n-p => t) ; yes to all - (mock (mastodon-tl--read-rules-ids) => '(1 2 3)) - (should (equal (mastodon-tl--report-params account toot) - '(("rule_ids[]" . 3) - ("rule_ids[]" . 2) - ("rule_ids[]" . 1) - ("account_id" . 42) - ("comment" . "Dummy complaint") - ("status_ids[]" . 61208) - ("forward" . "true"))))))))) + ("status_ids[]" . 61208) + ("forward" . "true"))))))))) (ert-deftest mastodon-tl--report-build-params () "" diff --git a/test/mastodon-toot-tests.el b/test/mastodon-toot-tests.el index 69333c0..6133453 100644 --- a/test/mastodon-toot-tests.el +++ b/test/mastodon-toot-tests.el @@ -40,7 +40,7 @@ Transfer-Encoding: chunked") (defconst mastodon-toot--mock-toot (propertize "here is a mock toot text." - 'toot-json mastodon-toot-test-base-toot)) + 'item-json mastodon-toot-test-base-toot)) (defconst mastodon-toot--multi-mention '((mentions . @@ -143,7 +143,7 @@ mention string." (with-mock (mock (mastodon-auth--user-acct) => "joebogus") ;; (mock (mastodon-toot--own-toot-p toot) => nil) - (mock (mastodon-tl--property 'toot-json) => mastodon-toot-test-base-toot) + (mock (mastodon-tl--property 'item-json) => mastodon-toot-test-base-toot) (mock (mastodon-tl--property 'base-toot) => toot) (should (equal (mastodon-toot--delete-toot) "You can only delete (and redraft) your own toots."))))) @@ -155,7 +155,7 @@ mention string." (let ((delete-response (current-buffer)) (toot mastodon-toot-test-base-toot)) (with-mock - (mock (mastodon-tl--property 'toot-json) => toot) + (mock (mastodon-tl--property 'item-json) => toot) (mock (mastodon-tl--property 'base-toot) => toot) ;; (mock (mastodon-toot--own-toot-p toot) => t) (mock (mastodon-auth--user-acct) => "acct42@example.space") @@ -175,12 +175,12 @@ mention string." (toot mastodon-toot-test-base-toot) (id 61208)) (with-mock - (mock (mastodon-tl--property 'base-toot-id) => id) + (mock (mastodon-tl--property 'base-item-id) => id) (mock (mastodon-http--api "statuses/61208/pin") => "https://example.space/statuses/61208/pin") (mock (mastodon-http--post "https://example.space/statuses/61208/pin") => pin-response) - (should (equal (mastodon-toot--action "pin" (lambda () + (should (equal (mastodon-toot--action "pin" (lambda (_) (message "Toot pinned!"))) "Toot pinned!")))))) @@ -190,7 +190,7 @@ mention string." (let ((pin-response (current-buffer)) (toot mastodon-toot-test-base-toot)) (with-mock - (mock (mastodon-tl--property 'toot-json) => toot) + (mock (mastodon-tl--property 'item-json) => toot) (mock (mastodon-tl--property 'base-toot) => toot) (mock (mastodon-auth--user-acct) => "joebogus@example.space") (should (equal (mastodon-toot--pin-toot-toggle) |