 (facts "about authorisation end-point"
        (fact "request with client-id, response_type and redirect_uri returns redirect to login page if there is no user session"
              (let [client-details (cl-client/register-client "ClientTestApp" "localhost:3001") ;FORMAT => {:client-secret "XLFCQRKJXSV3T6YQJL5ZJJVGFUJNT6LD", :client-id "RXBX6ZXAER5KPDSZ3ZCZJDOBS27FLDE7", :name "ClientTestApp", :url "localhost:3001"}
-                   request (-> (r/request :get "/authorisation" {:client_id (:client-id client-details) :response_type "code" :redirect_uri "callback"})
-                               (assoc :params {:client_id (:client-id client-details) :response_type "code" :redirect_uri "callback"})
+                   request (-> (create-request :get (routes/path :authorise)
+                                               {:client_id (:client-id client-details)
+                                                :response_type "code"
+                                                :redirect_uri "callback"})
                                (r/header "accept" "text/html"))
                    response (oauth/authorise request)]
                (:status response) => 302


(facts "about auto-approver"
       (fact "returns true if user has authorised the client"
             (-> (r/request :get "/authorisation")
                 (assoc :params {:client_id ...client-id...})
                 (assoc-in [:session :user-login] ...email...)
                 oauth/auto-approver) => true
             (provided
               (user/is-authorised-client-for-user? ...email... ...client-id...) => true))

       (fact "returns false if user has not authorised the client"
             (-> (r/request :get "/authorisation")
                 (assoc :params {:client_id ...client-id...})
                 (assoc-in [:session :user-login] ...email...)
                 oauth/auto-approver) => false
             (provided

                   client-details (cl-client/register-client "MYAPP" "myapp.com")
                   updated-user (user/add-authorised-client-for-user! user-email (:client-id client-details))
                   access-token (cl-token/create-token client-details user)
                   request (-> (create-request :get (routes/path :authorise)
                                               {:client_id (:client-id client-details) :response_type "code"
                                                :redirect_uri "callback"})
                               (assoc-in [:session :access_token] (:token access-token))
                               (assoc-in [:session :user-login] (:login user)))
                   response (oauth/authorise request)]
