aboutsummaryrefslogtreecommitdiff
path: root/test/mastodon-client-tests.el
diff options
context:
space:
mode:
authorH Durer <h.duerer@gmail.com>2018-03-02 20:25:15 +0000
committerGitHub <noreply@github.com>2018-03-02 20:25:15 +0000
commitca4bb2a436f1ba46515b812c97d74333294bae76 (patch)
treeda489813900e660e5d9460ed1a9c9b13869d344a /test/mastodon-client-tests.el
parent3e9bdbf2eeecafd7bb0673f2709f816a740c7d61 (diff)
parentb1f05c07c8f00e4546b1ff07be47537660a0b5f6 (diff)
Merge pull request #154 from hdurer/multi-instance-in-plstore
Keep track of to which instance secrets in plstore belong
Diffstat (limited to 'test/mastodon-client-tests.el')
-rw-r--r--test/mastodon-client-tests.el72
1 files changed, 50 insertions, 22 deletions
diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el
index c339efa..dfe175b 100644
--- a/test/mastodon-client-tests.el
+++ b/test/mastodon-client-tests.el
@@ -9,7 +9,8 @@
("redirect_uris" . "urn:ietf:wg:oauth:2.0:oob")
("scopes" . "read write follow")
("website" . "https://github.com/jdenen/mastodon.el"))
- nil))
+ nil
+ :unauthenticated))
(mastodon-client--register)))
(ert-deftest fetch ()
@@ -23,53 +24,80 @@
(ert-deftest store-1 ()
"Should return the client plist."
- (let ((plist '(:client_id "id" :client_secret "secret")))
+ (let ((mastodon-instance-url "http://mastodon.example")
+ (plist '(:client_id "id" :client_secret "secret")))
(with-mock
(mock (mastodon-client--token-file) => "stubfile.plstore")
(mock (mastodon-client--fetch) => '(:client_id "id" :client_secret "secret"))
(let* ((plstore (plstore-open "stubfile.plstore"))
- (client (delete "mastodon" (plstore-get plstore "mastodon"))))
- (should (equal (mastodon-client--store) plist))
- ))))
+ (client (cdr (plstore-get plstore "mastodon-http://mastodon.example"))))
+ (should (equal (mastodon-client--store) plist))))))
(ert-deftest store-2 ()
"Should store client in `mastodon-client--token-file'."
- (let* ((plstore (plstore-open "stubfile.plstore"))
- (client (delete "mastodon" (plstore-get plstore "mastodon"))))
+ (let* ((mastodon-instance-url "http://mastodon.example")
+ (plstore (plstore-open "stubfile.plstore"))
+ (client (cdr (plstore-get plstore "mastodon-http://mastodon.example"))))
(plstore-close plstore)
(should (string= (plist-get client :client_id) "id"))
(should (string= (plist-get client :client_secret) "secret"))))
-(ert-deftest read-1 ()
+(ert-deftest read-finds-match ()
"Should return mastodon client from `mastodon-token-file' if it exists."
- (with-mock
- (mock (mastodon-client--token-file) => "fixture/client.plstore")
- (should (equal (mastodon-client--read) '(:client_id "id" :client_secret "secret")))))
+ (let ((mastodon-instance-url "http://mastodon.example"))
+ (with-mock
+ (mock (mastodon-client--token-file) => "fixture/client.plstore")
+ (should (equal (mastodon-client--read)
+ '(:client_id "id2" :client_secret "secret2"))))))
+
+(ert-deftest read-finds-no-match ()
+ "Should return mastodon client from `mastodon-token-file' if it exists."
+ (let ((mastodon-instance-url "http://mastodon.social"))
+ (with-mock
+ (mock (mastodon-client--token-file) => "fixture/client.plstore")
+ (should (equal (mastodon-client--read) nil)))))
-(ert-deftest read-2 ()
+(ert-deftest read-empty-store ()
"Should return nil if mastodon client is not present in the plstore."
(with-mock
(mock (mastodon-client--token-file) => "fixture/empty.plstore")
(should (equal (mastodon-client--read) nil))))
-(ert-deftest client-1 ()
- "Should return `mastondon-client' if non-nil."
- (let ((mastodon-client--client-details t))
- (should (eq (mastodon-client) t))))
+(ert-deftest client-set-and-matching ()
+ "Should return `mastondon-client' if `mastodon-client--client-details-alist' is non-nil and instance url is included."
+ (let ((mastodon-instance-url "http://mastodon.example")
+ (mastodon-client--client-details-alist '(("https://other.example" . :no-match)
+ ("http://mastodon.example" . :matches))))
+ (should (eq (mastodon-client) :matches))))
+
+(ert-deftest client-set-but-not-matching ()
+ "Should read from `mastodon-token-file' if wrong data is cached."
+ (let ((mastodon-instance-url "http://mastodon.example")
+ (mastodon-client--client-details-alist '(("http://other.example" :wrong))))
+ (with-mock
+ (mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar"))
+ (should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar")))
+ (should (equal mastodon-client--client-details-alist
+ '(("http://mastodon.example" :client_id "foo" :client_secret "bar")
+ ("http://other.example" :wrong)))))))
-(ert-deftest client-2 ()
+(ert-deftest client-unset ()
"Should read from `mastodon-token-file' if available."
- (let ((mastodon-client--client-details nil))
+ (let ((mastodon-instance-url "http://mastodon.example")
+ (mastodon-client--client-details-alist nil))
(with-mock
(mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar"))
(should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar")))
- (should (equal mastodon-client--client-details '(:client_id "foo" :client_secret "bar"))))))
+ (should (equal mastodon-client--client-details-alist
+ '(("http://mastodon.example" :client_id "foo" :client_secret "bar")))))))
-(ert-deftest client-3 ()
+(ert-deftest client-unset-and-not-in-storage ()
"Should store client data in plstore if it can't be read."
- (let ((mastodon-client--client-details nil))
+ (let ((mastodon-instance-url "http://mastodon.example")
+ (mastodon-client--client-details-alist nil))
(with-mock
(mock (mastodon-client--read))
(mock (mastodon-client--store) => '(:client_id "foo" :client_secret "baz"))
(should (equal (mastodon-client) '(:client_id "foo" :client_secret "baz")))
- (should (equal mastodon-client--client-details '(:client_id "foo" :client_secret "baz"))))))
+ (should (equal mastodon-client--client-details-alist
+ '(("http://mastodon.example" :client_id "foo" :client_secret "baz")))))))