1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-07 02:33:39 +02:00

Save login credentials in local storage

Squashed commit of the following:

commit b480676cef
Author: Arne Schlüter <arne@schlueter.is>
Date:   Wed May 30 18:38:40 2018 +0200

    Remember login credentials

commit ed060e55b6
Author: Arne Schlüter <arne@schlueter.is>
Date:   Wed May 30 14:45:11 2018 +0200

    Add tests for auth process

commit ca8972f8c3
Author: Arne Schlüter <arne@schlueter.is>
Date:   Wed May 30 13:34:38 2018 +0200

    Make sure to always run tests in development
This commit is contained in:
Arne Schlüter 2018-05-30 18:40:42 +02:00
commit 3376e01930
8 changed files with 111 additions and 46 deletions

View file

@ -0,0 +1,29 @@
(ns airsonic-ui.events-test
(:require [cljs.test :refer [deftest testing is]]
[clojure.string :as str]
[airsonic-ui.events :as events]))
(enable-console-print!)
(deftest authentication
(testing "Credential verification"
(let [server "https://localhost"
fx (events/authenticate {:db {}} [:_ "user" "pass" server])
request (:http-xhrio fx)]
(testing "uses correct server url"
(is (str/starts-with? (:uri request) server))
(is (str/includes? (:uri request) "/ping")))
(testing "saves the given server location"
(is (= server (get-in fx [:db :credentials :server]))))
(testing "invokes correct success callback"
(is (= ::events/credentials-verified (first (:on-success request)))))))
(testing "On succesfull response"
(let [fx (events/credentials-verified {:db {}} [:_ "user" "pass"])
credentials {:u "user" :p "pass"}]
(testing "credentials are sent to the router for access rights"
(is (= credentials (:routes/set-credentials fx))))
(testing "credentials are saved in the global state"
(is (= credentials (-> (get-in fx [:db :credentials])
(select-keys [:u :p])))))
(testing "the login process is finalized"
(is (= [::events/logged-in] (:dispatch fx)))))))