테스트 코드 짜다가 에러 핸들러 잘못된거 발견하고 고침.


젖나 잘된다!




(expect "Hello World!" (http-get ["node"] :content-type :text))


(expect [99 false true nil 401]

        (let [iat-sec 100

              exp-sec 99

              now (quot (System/currentTimeMillis) 1000)

              [expired-jwt iat exp] (make-jwt-info god-identity exp-sec (time/minus (tconv/from-long (* now 1000)) (time/seconds iat-sec)))

              http-expired-options (assoc-in http-json-options [:headers "x-auth-token"] expired-jwt)]


          [(- exp iat)

           (<= iat now exp)

           (boolean (#{1 2} (- now exp)))

           (req->identity http-expired-options)

           (http-get ["company"]

                     :url-params {:$select "name"}

                     :auth http-expired-options

                     :get-keys [:status])]))


(expect [3 true true true 200]

        (let [exp-sec 3

              now (quot (System/currentTimeMillis) 1000)

              [jwt iat exp] (make-jwt-info god-identity exp-sec (tconv/from-long (* now 1000)))

              http-options (assoc-in http-json-options [:headers "x-auth-token"] jwt)]


          [(- exp iat)

           (<= iat now exp)

           (boolean ((set (range 1 (inc exp-sec))) (- exp now)))

           (instance? ClientIdentity (req->identity http-options))

           (http-get ["company"]

                     :url-params {:$select "name"}

                     :auth http-options

                     :get-keys [:status])]))


(expect 401 ;; without Auth ID

        (http-post ["oauth"]

                   :auth http-oauth-options

                   :url-params {"provider" "facebook"}

                   :form-params {:oauth-action (json/generate-string {:action :follow :provider :facebook :url "facebook:object-id:123"})}

                   :get-keys [:status]))


(expect Oauth

        (-> (http-post ["oauth"]

                       :auth (->> 5

                                  time/seconds

                                  (make-jwt-str god-identity)

                                  (assoc-in http-oauth-options [:headers "x-auth-token"]))

                       :url-params {"provider" "facebook"}

                       :form-params {:oauth-action (json/generate-string {:action :follow :provider :facebook :url "facebook:object-id:123"})}

                       :get-keys [:opts :url])

            codec/form-decode

            (get "cancel_url")

            codec/form-decode

            (get "state")

            evict-oauth-from-lru

            first

            second))


(expect 422 ;; unprocessable

        (http-post ["company"]

                   :auth (->> 5

                              time/seconds

                              (make-jwt-str god-identity)

                              ;; Provide valid but wrong content header

                              (assoc-in http-oauth-options [:headers "x-auth-token"]))

                   :body (json/generate-string test-company1)

                   :get-keys [:status]))


(expect 404

        (http-post ["company"]

                   :auth (->> 5

                              time/seconds

                              (make-jwt-str god-identity)

                              ;; Provide wrong content header

                              (assoc-in {:headers {"Content-Type" "text/html"}} [:headers "x-auth-token"]))

                   :body (json/generate-string test-company1)

                   :get-keys [:status]))


(expect test-company1

        (select-keys (http-post ["company"]

                                :auth (make-god-json-options)

                                :body (json/generate-string test-company1)

                                :get-keys [:body])

                     (keys test-company1)))



(expect test-company2

        (select-keys (http-post ["company"]

                                :auth (make-god-json-options)

                                :body (json/generate-string test-company2)

                                :get-keys [:body])

                     (keys test-company2)))


(expect test-company1

        (select-keys (first (http-get ["company"] :url-params {:$filter "name=test-company1" :$select "name,description,postcode"}

                                      :auth (make-god-json-options)

                                      :get-keys [:body]))

                     (keys test-company1)))



(expect (select-keys test-company2 [:name :description :postcode])

        (select-keys (first (http-get ["company"] :url-params {:$filter "name=test-company2" :$select "name,description,postcode"}

                                      :auth (make-god-json-options)

                                      :get-keys [:body]))

                     (keys test-company2)))



(expect (map #(select-keys % [:name :description :postcode])

             [test-company1 test-company2])

        (map #(select-keys % [:name :description :postcode])

             (http-get ["company"] :url-params {:$filter "name like test%" :$select "name,description,postcode,address1,address2"}

                       :auth (make-god-json-options)

                       :get-keys [:body])))



(expect true

        (let [company-oid (-> ["company"]

                               (http-get :url-params {:$filter "name=test-company1" :$select "oid"}

                                         :auth (make-god-json-options)

                                         :get-keys [:body])

                               first

                               :oid)]

          (= company-oid

             (:oid (http-get ["company" company-oid] :auth (make-god-json-options) :get-keys [:body])))))



(expect test-company-account1

        (let [company-oid (-> ["company"]

                               (http-get :url-params {:$filter "name=test-company1" :$select "oid"}

                                         :auth (make-god-json-options)

                                         :get-keys [:body])

                               first

                               :oid)]

          (select-keys (http-post ["company" company-oid "account"]

                                  :auth (make-god-json-options)

                                  :body (json/generate-string (assoc test-company-account1 :company-oid company-oid))

                                  :get-keys [:body])

                       (keys test-company-account1))))



(expect 409

        (let [company-oid (-> ["company"]

                               (http-get :url-params {:$filter "name=test-company1" :$select "oid"}

                                         :auth (make-god-json-options)

                                         :get-keys [:body])

                               first

                               :oid)]

          (http-post ["company" company-oid "account"]

                     :auth (make-god-json-options)

                     :body (json/generate-string (assoc test-company-account2 :company-oid company-oid))

                                  

                     :get-keys [:status])))