From 24e038facf1a17d4996a9bca400aa6fe5ebf310b Mon Sep 17 00:00:00 2001 From: Johnson Denen Date: Tue, 11 Apr 2017 23:54:33 -0400 Subject: Add store-client-id-and-secret test Add `mastodon-auth--token-file' function Add test for `mastodon-auth--token-file' --- test/mastodon-auth-tests.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/mastodon-auth-tests.el') diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el index 371abcc..0012e3e 100644 --- a/test/mastodon-auth-tests.el +++ b/test/mastodon-auth-tests.el @@ -1,6 +1,13 @@ (require 'el-mock) + +(load-file "../lisp/mastodon.el") +(load-file "../lisp/mastodon-http.el") (load-file "../lisp/mastodon-auth.el") +(ert-deftest mastodon-auth:token-file () + "Should return `mastodon-token-file' value." + (should (string= (mastodon-auth--token-file) "~/.emacs.d/mastodon.plstore"))) + (ert-deftest mastodon-auth:registration-success () "Should set `mastodon--client-app-plist' on succesful registration." (let ((hash (make-hash-table :test 'equal)) @@ -42,3 +49,20 @@ (with-mock (mock (mastodon--register-client-app) => app-plist) (should (equal app-plist (mastodon--register-and-return-client-app)))))) + +(defun helper:read-plstore (file key) + (let* ((plstore (plstore-open file)) + (masto (delete "mastodon" (plstore-get plstore "mastodon")))) + (progn + (plstore-close plstore) + (plist-get masto key)))) + +(ert-deftest mastodon-auth:store-client-id-and-secret () + "Should create plstore from client plist. Should return plist." + (let ((app-plist '(:client_id "id-val" :client_secret "secret-val"))) + (with-mock + (mock (mastodon--register-and-return-client-app) => app-plist) + (mock (mastodon-auth--token-file) => "stubfile.plstore") + (should (eq app-plist (mastodon--store-client-id-and-secret))) + (should (string= (helper:read-plstore (mastodon-auth--token-file) :client_id) "id-val")) + (should (string= (helper:read-plstore (mastodon-auth--token-file) :client_secret) "secret-val"))))) -- cgit v1.2.3