mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Squashed commit of the following:
commit 393c481a21fa97881be2b6859e9acaa8ab7abb7f
Author: Arne Schlüter <arne@schlueter.is>
Date: Wed Sep 5 12:04:56 2018 +0200
Consider user roles when building up the navigation
commit d631cba1174ecf42b682664bf57c41b88b7f5ed4
Author: Arne Schlüter <arne@schlueter.is>
Date: Wed Sep 5 11:52:05 2018 +0200
Save user roles on login
commit e68ced335ccc11a2daebbf12bb4061a53935c268
Author: Arne Schlüter <arne@schlueter.is>
Date: Wed Sep 5 10:25:19 2018 +0200
Rename dispatch to muted-dispatch for easier disambiguation
67 lines
3.3 KiB
Clojure
67 lines
3.3 KiB
Clojure
(ns airsonic-ui.subs-test
|
|
(:require [cljs.test :refer [deftest testing is]]
|
|
[airsonic-ui.fixtures :as fixtures]
|
|
[airsonic-ui.api.helpers :as api]
|
|
[airsonic-ui.events :as events]
|
|
[airsonic-ui.subs :as subs]))
|
|
|
|
(deftest booting
|
|
(let [route [:some-route nil nil]
|
|
verified-credentials (assoc fixtures/credentials :verified? true)
|
|
is-booting? (fn is-booting? [db]
|
|
(subs/is-booting? db [:subs/is-booting?]))]
|
|
(testing "Should be false when we don't have previous credentials"
|
|
(is (not (is-booting? {:routes/current-route route})))
|
|
(is (not (is-booting? {:routes/current-route route
|
|
:credentials {}}))) )
|
|
(testing "Should be true when we have unverified credentials"
|
|
(is (true? (is-booting? {:routes/current-route route
|
|
:credentials fixtures/credentials}))))
|
|
(testing "Should be false when we have verified credentials"
|
|
(is (not (is-booting? {:routes/current-route route
|
|
:credentials verified-credentials}))))
|
|
(testing "Should be true when routing is not yet set up"
|
|
(is (true? (is-booting? {:routes/current-route nil
|
|
:credentials verified-credentials}))))))
|
|
|
|
(deftest cover-images
|
|
(let [credentials {:server "https://foo.bar"
|
|
:u "test-user"
|
|
:p "some-random-password"}]
|
|
(testing "Should give the correct path once the credentials are set"
|
|
(is (= (api/cover-url (:server credentials)
|
|
(select-keys credentials [:u :p])
|
|
fixtures/song
|
|
48)
|
|
(subs/cover-url [credentials] [:subs/cover-image fixtures/song 48]))))))
|
|
|
|
(def successful-auth-db
|
|
"For the details see event_test.cljs"
|
|
(-> {:store {:credentials fixtures/credentials}}
|
|
(events/initialize-app [::events/initialize-app])
|
|
(events/authentication-response [:credentials/authentication-response (:auth-success fixtures/responses)])
|
|
(events/authentication-success [:credentials/authentication-success fixtures/credentials (:auth-success fixtures/responses)])
|
|
(:db)))
|
|
|
|
(deftest user-roles
|
|
(testing "Should be available after a successful authentication"
|
|
(let [user-roles (-> (subs/user-info successful-auth-db [:user/info])
|
|
(subs/user-roles [:user/roles]))]
|
|
(is (set? user-roles))
|
|
(is (every? keyword? user-roles))
|
|
(is (not (user-roles :username)) "and contain only roles")))
|
|
(testing "Should indicate whether a user has a given role"
|
|
(letfn [(role [role]
|
|
(-> (subs/user-info successful-auth-db [:user/info])
|
|
(subs/user-roles [:user/roles])
|
|
(disj :admin) ; <- makes sure we're not allowed everything
|
|
(subs/user-role [:user/role role])))]
|
|
(is (some? (role :stream)))
|
|
(is (not (some? (role :video-conversion))))))
|
|
(testing "Should allow everything to an admin"
|
|
(letfn [(admin-role [role]
|
|
(-> (subs/user-info successful-auth-db [:user/info])
|
|
(subs/user-roles [:user/roles])
|
|
(subs/user-role [:user/role role])))]
|
|
(is (some? (admin-role :stream)))
|
|
(is (some? (admin-role :video-conversion))))))
|