              (let [user (user/store-user! user-email "password")
                    client-details (cl-client/register-client "MYAPP" "myapp.com")
                    access-token (cl-token/create-token client-details user)
-                   request (-> (r/request :post "/authorisation")
-                               (assoc :params {:client_id (:client-id client-details) :response_type "code" :redirect_uri "callback"})
+                   request (-> (create-request :post (routes/path :authorise) nil)
+                               (assoc :params {: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))
                                ;; stale csrf token can cause session to be lost

(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"})
                               (r/header "accept" "text/html"))
                   response (oauth/authorise request)]
               (:status response) => 302

  (:import (org.apache.commons.codec.binary Base64)))

(defn create-request [method url params]
  (-> (r/request method url params)
      (assoc :params params)
      (assoc-in [:context :translator] {})))

