 (ns stonecutter.test.controller.oauth
   (:require [midje.sweet :refer :all]
-            [stonecutter.controller.oauth :as oauth]
             [ring.mock.request :as r]
-            [clauth.client :as client]
-            [clauth.token :as token]
-            [clauth.user :as user]
-            [clauth.auth-code :as auth-code]
+            [clauth.client :as cl-client]
+            [clauth.token :as cl-token]
+            [clauth.auth-code :as cl-auth-code]
             [cheshire.core :as json]
-            [stonecutter.controller.user :as u]
             [stonecutter.controller.oauth :as oauth]
             [stonecutter.db.storage :as storage])
   (:import (org.apache.commons.codec.binary Base64)))

(facts "about token endpoint"
       (let [user-email "email@user.com"
             user (storage/store-user! user-email "password")
             client-details (client/register-client "MYAPP" "myapp.com")
             auth-code (auth-code/create-auth-code client-details user "callback")
             request (-> (r/request :get "/token")
                         (assoc :params {:grant_type   "authorization_code"
                                         :redirect_uri "callback"

       (fact "user-email and access_token in session stay in session if user is logged in"
             (let [user-email "email@user.com"
                   user (storage/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"})
                               (assoc-in [:session :access_token] (:token access-token))
