1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-07 02:33:39 +02:00
airsonic-ui/test/cljs/airsonic_ui/subs_test.cljs
Arne Schlüter fa485bbf42 Merge incomplete podcast support
commit 4ac35d6530f7770e7b80307321c72541a55e2c8e
Author: Arne Schlüter <arne@schlueter.is>
Date:   Mon Oct 8 21:09:04 2018 +0200

    Stub out podcast detail view

commit 60742a22e93bfe6f432e06d56d3e4da671184559
Author: Arne Schlüter <arne@schlueter.is>
Date:   Tue Sep 18 23:02:39 2018 +0200

    Simplify api helpers; closes #16

commit 8bbc79ebf4dbbe3dbfa08cb4c7c1edd341d507eb
Author: Arne Schlüter <arne@schlueter.is>
Date:   Tue Sep 18 19:39:17 2018 +0200

    Adjust `stream-url` to work with podcast episodes

commit 991ba5b65230a7429c160ca1b7968ecbb8595e0b
Author: Arne Schlüter <arne@schlueter.is>
Date:   Tue Sep 18 19:14:08 2018 +0200

    Fix breadcrumbs for podcasts

commit 37c3a894eded2fe37f9af031d3132c7175702266
Author: Arne Schlüter <arne@schlueter.is>
Date:   Tue Sep 18 15:11:54 2018 +0200

    Stub out overview for podcasts
2018-10-08 21:15:56 +02:00

66 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}))))
(testing "Should be false when an error occurred"
(is (false? (is-booting? (:db (events/show-notification {} [:_ :error "Something bad happened"]))))))))
(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 credentials 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))))))