diff options
author | Abhiseck Paira <abhiseckpaira@disroot.org> | 2022-02-16 21:59:15 +0530 |
---|---|---|
committer | Abhiseck Paira <abhiseckpaira@disroot.org> | 2022-02-16 21:59:15 +0530 |
commit | 77c173afc1f24fa371c41d0c59b94a8650eb4f61 (patch) | |
tree | 17744a553c0affa362e060da358e68dc83ab84ff /test | |
parent | f1ef6f7c8accc7ce3fd44373776727afe3d8957c (diff) |
test: add more test
Add the following tests:
* mastodon-client--current-user-active-p
* mastodon-client-store-access-token
* mastodon-client-make-user-active
* mastodon-client-form-user-from-vars
Diffstat (limited to 'test')
-rw-r--r-- | test/mastodon-client-tests.el | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index 3c667b1..c2ec50c 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -121,3 +121,54 @@ (should (equal (mastodon-client) '(:client_id "foo" :client_secret "baz"))) (should (equal mastodon-client--client-details-alist '(("http://mastodon.example" :client_id "foo" :client_secret "baz"))))))) + +(ert-deftest mastodon-client-form-user-from-vars () + (let ((mastodon-active-user "test9000") + (mastodon-instance-url "https://mastodon.example")) + (should + (equal (mastodon-client-form-user-from-vars) + "test9000@mastodon.example")))) + +(ert-deftest mastodon-client--current-user-active-p () + (let ((mastodon-active-user "test9000") + (mastodon-instance-url "https://mastodon.example")) + ;; when the current user /is/ the active user + (with-mock + (mock (mastodon-client--general-read "active-user") => '(:username "test9000@mastodon.example" :client_id "id1")) + (should (equal (mastodon-client--current-user-active-p) + '(:username "test9000@mastodon.example" :client_id "id1")))) + ;; when the current user is /not/ the active user + (with-mock + (mock (mastodon-client--general-read "active-user") => '(:username "user@other.example" :client_id "id1")) + (should (null (mastodon-client--current-user-active-p)))))) + +(ert-deftest mastodon-client-store-access-token () + (let ((mastodon-instance-url "https://mastodon.example") + (mastodon-active-user "test8000") + (user-details + '(:username "test8000@mastodon.example" + :instance "https://mastodon.example" + :client_id "id" :client_secret "secret" + :access_token "token"))) + ;; test if mastodon-client-store-access-token /returns/ right + ;; value + (with-mock + (mock (mastodon-client) => '(:client_id "id" :client_secret "secret")) + (mock (mastodon-client--token-file) => "stubfile.plstore") + (should (equal (mastodon-client-store-access-token "token") + user-details))) + ;; test if mastodon-client-store-access-token /stores/ right value + (with-mock + (mock (mastodon-client--token-file) => "stubfile.plstore") + (should (equal (mastodon-client--general-read + "user-test8000@mastodon.example") + user-details))) + (delete-file "stubfile.plstore"))) + +(ert-deftest mastodon-client-make-user-active () + (let ((user-details '(:username "test@mastodon.example"))) + (with-mock + (mock (mastodon-client--token-file) => "stubfile.plstore") + (mastodon-client-make-user-active user-details) + (should (equal (mastodon-client--general-read "active-user") + user-details))))) |