 (ns stonecutter.test.controller.user
   (:require [midje.sweet :refer :all]
+            [ring.mock.request :as mock]
+            [clauth.token :as cl-token]
+            [clauth.client :as cl-client]
+            [clauth.user :as cl-user]
+            [net.cgrand.enlive-html :as html]
             [stonecutter.controller.user :as c]
-            [ring.mock.request :as mock]
             [stonecutter.db.storage :as s]
-            [stonecutter.validation :as v]
-            [clauth.client :as client]
-            [clauth.token :as token]
-            [clauth.user :as user-store]
-            [clauth.store :as clauth-store]
-            [net.cgrand.enlive-html :as html]))
+            [stonecutter.validation :as v]))
 
 (def email "valid@email.com")
 (def password "password")

   :name     nil
   :url      nil})

(background (before :facts (user-store/reset-user-store!)))

(fact "user can sign in with valid credentials and is redirected to profile, with user and access_token added to session"
      (-> (create-request :post "/sign-in" sign-in-user-params)

            :session) => empty?
        (provided
          (s/authenticate-and-retrieve-user email password) => ...user...
          (cl-client/fetch-client "client-id") => ...client...
          (cl-token/create-token ...client... ...user...) => {:token ...token...})))

(fact "if user has client id but no return-to in session, throws an exception"
      (-> (create-request :post "/sign-in" sign-in-user-params)
