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

Add user notifications and display api errors (#10)

Closes #2 

* Add user notifications

* Update re-frame-10x config

* Display api errors as notifications

* Automatically hide notifications after a while
This commit is contained in:
Arne Schlüter 2018-06-11 19:58:13 +02:00 committed by GitHub
commit ab7519f289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 232 additions and 42 deletions

View file

@ -1,6 +1,7 @@
(ns airsonic-ui.utils.api-test
(:require [cljs.test :refer [deftest testing is]]
[clojure.string :as str]
[airsonic-ui.fixtures :refer [responses]]
[airsonic-ui.utils.api :as api]))
(defn- url
@ -30,3 +31,19 @@
(is (true? (str/includes? (api/cover-url "http://server.tld" {} album -1) (str "id=" (:coverArt album))))))
(testing "Should scale an image to a given size"
(is (true? (str/includes? (api/cover-url "http://server.tld" {} album 48) "size=48"))))))
(deftest response-handling
(testing "Should unwrap responses"
(let [response (:ok responses)]
(is (= (get-in response [:subsonic-response :scanStatus])
(api/unwrap-response response)))))
(testing "Should detect errors"
(is (true? (api/is-error? (:error responses))))
(is (false? (api/is-error? (:ok responses)))))
(testing "Should throw an informative error when trying to unwrap an erroneous response"
(let [error-response (:error responses)]
(is (thrown? ExceptionInfo (api/unwrap-response error-response)))
(try
(api/unwrap-response error-response)
(catch ExceptionInfo e
(= (:error error-response) (ex-data e)))))))