                           :attrs
                           :value)) => "client-id"
                     (provided
-                      (user/is-authorised-client-for-user? @storage/user-store ...email... "client-id") => true
-                      (c/retrieve-client anything "client-id") => {:client-id "client-id" :name "CLIENT_NAME"}))
+                     (user/is-authorised-client-for-user? ...user-store... ...email... "client-id") => true
+                     (c/retrieve-client anything "client-id") => {:client-id "client-id" :name "CLIENT_NAME"}))
 
               (fact "client name is correctly shown on the page"
                     (let [element-has-correct-client-name-fn (fn [element] (= (html/text element) "CLIENT_NAME"))
                           request (th/create-request :get (routes/path :show-unshare-profile-card)
                                                   {:client_id "client-id"}
                                                   {:user-login ...email...})]
-                      (-> (u/show-unshare-profile-card @storage/user-store request)
+                      (-> (u/show-unshare-profile-card ...user-store... request)
                           :body
                           html/html-snippet
                           (html/select [:.clj--client-name])) => (has some element-has-correct-client-name-fn)
                       (provided
-                        (user/is-authorised-client-for-user? @storage/user-store ...email... "client-id") => true
-                        (c/retrieve-client anything "client-id") => {:client-id "client-id" :name "CLIENT_NAME"})))
+                       (user/is-authorised-client-for-user? ...user-store... ...email... "client-id") => true
+                       (c/retrieve-client anything "client-id") => {:client-id "client-id" :name "CLIENT_NAME"})))
 
               (fact "missing client_id query param responds with 404"
                     (->> (th/create-request :get (routes/path :show-unshare-profile-card) nil)
-                         (u/show-unshare-profile-card @storage/user-store)) => {:status 404})
+                         (u/show-unshare-profile-card ...user-store...)) => {:status 404})
 
               (fact "user is redirected to /profile if client_id is not in user's list of authorised clients"
                     (->> (th/create-request :get (routes/path :show-unshare-profile-card)
                                          {:client_id ...client-id...}
                                          {:user-login ...email...})
-                         (u/show-unshare-profile-card @storage/user-store)) => (check-redirects-to "/profile")
-                    (provided
-                      (user/is-authorised-client-for-user? @storage/user-store ...email... ...client-id...) => false)))
+                         (u/show-unshare-profile-card ...user-store...)) => (check-redirects-to "/profile")
+                    (provided
+                     (user/is-authorised-client-for-user? ...user-store... ...email... ...client-id...) => false)))
 
        (facts "about post requests to /unshare-profile-card"
               (fact "posting to /unshare-profile-card with client-id in the form params should remove client-id from the user's authorised clients and then redirect the user to the profile page"
                     (->> (th/create-request :post "/unshare-profile-card" {:client_id "client-id"} {:user-login "user@email.com"})
-                         (u/unshare-profile-card @storage/user-store)) => (check-redirects-to "/profile")
-                    (provided
-                      (user/remove-authorised-client-for-user! @storage/user-store "user@email.com" "client-id") => anything))))
+                         (u/unshare-profile-card ...user-store...)) => (check-redirects-to "/profile")
+                    (provided
+                     (user/remove-authorised-client-for-user! ...user-store... "user@email.com" "client-id") => anything))))


(facts "about registration"
       (fact "user can register with valid credentials and is redirected to profile-created page, with user-login and access_token added to session"
             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params {:some "session-data"})
                                 (u/register-user @storage/user-store))
                   registered-user (user/retrieve-user @storage/user-store email)]
               response => (check-redirects-to (routes/path :show-profile-created))
               response => (contains {:session (contains {:user-login   (:login registered-user)
                                                          :access_token (complement nil?)})})))

       (fact "session is not lost when redirecting from registration"
             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params {:some "session-data"})
                                 (u/register-user @storage/user-store))]
               response => (check-redirects-to (routes/path :show-profile-created))
               response => (contains {:session (contains {:some "session-data"})})))

       (fact "user data is saved"
             (->> (th/create-request :post (routes/path :register-user) register-user-params)
                  (u/register-user @storage/user-store)) => anything
             (provided
               (user/store-user! @storage/user-store "valid@email.com" "password") => ...user...))

       (fact "user is send a confirmation email with the correct content"
             (against-background
               (uuid/uuid) => confirmation-id)
             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params)
                                 (u/register-user @storage/user-store))
                   registered-user (user/retrieve-user @storage/user-store email)]
               (:email @most-recent-email) => email
               (:body @most-recent-email) => (contains {:confirmation-id confirmation-id})))

       (fact "when user email is send, flash message is assoc-ed in redirect"
             (against-background
               (uuid/uuid) => confirmation-id)
             (let [response (->> (th/create-request :post (routes/path :register-user) register-user-params)
                                 (u/register-user @storage/user-store))]
               (:flash response) => :confirm-email-sent)))

(facts "about registration validation errors"
       (fact "email must not be a duplicate"
             (let [html-response (->> (th/create-request :post "/register" register-user-params)
                                      (u/register-user @storage/user-store)
                                      :body
                                      html/html-snippet)]
               (-> (html/select html-response [:.form-row--validation-error])

                      (v/validate-change-password ...invalid-params...) => {:new-password :too-short}))

              (fact "when authorisation fails"
                    (-> (u/change-password ...user-store... (th/create-request :post "/change-password" ...params-with-wrong-current-password...))
                        :body
                        html/html-snippet
                        (html/select [:.clj--validation-summary__item])) =not=> empty?
