Skip to content

Instantly share code, notes, and snippets.

@swlkr
Created February 25, 2017 22:21
Show Gist options
  • Save swlkr/263a713e6a7bd44eec6541e4bfe300a2 to your computer and use it in GitHub Desktop.
Save swlkr/263a713e6a7bd44eec6541e4bfe300a2 to your computer and use it in GitHub Desktop.
(ns monolith.stripe.http-test
(:require [clojure.test :refer :all]
[monolith.stripe.http :refer :all])
(:refer-clojure :exclude [get])
(:import (java.util Date)
(java.text SimpleDateFormat)))
(deftest make-url-test
(testing "nil"
(is (= "" (make-url nil))))
(testing "valid value"
(is (= "hello/world" (make-url "hello/world"))))
(testing "valid url"
(is (= "https://api.stripe.com/v1/" (make-url "https://api.stripe.com/v1/"))))
(testing "double slash after protocol"
(is (= "https://api.com/hello" (make-url "https://api.com//hello")))))
(deftest req-body-test
(testing "nil"
(is (= {:body ""} (req-body nil))))
(testing "random key"
(is (= {:body ""} (req-body {:hello nil}))))
(testing "body"
(is (= {:body "{\"hello\":\"world\"}"} (req-body {:body {:hello "world"}}))))
(testing "form-params"
(is (= {:form-params {"hello" "world"}} (req-body {:form-params {:hello "world"}})))))
(deftest req-test
(let [headers {"Authorization" "Bearer "}]
(testing "nils"
(is (= {:url "" :method nil :headers headers} (req nil nil nil))))
(testing "2nd arity nils"
(is (= {:url "" :method nil :headers headers :body ""} (req nil nil nil nil))))
(testing "valid get request"
(is (= {:url "https://api.com/hello" :method :get :headers headers} (get "/hello" {:stripe-url "https://api.com/"}))))
(testing "valid post request"
(is (= {:url "https://api.com/hello"
:method :post
:headers headers
:body "{\"hello\":\"world\"}"} (post "/hello" {:body {:hello "world"}} {:stripe-url "https://api.com/"}))))
(testing "valid post request with form-data"
(is (= {:url "https://api.com/hello"
:method :post
:headers headers
:form-params {"hello" "world"}} (post "/hello" {:form-params {:hello "world"}} {:stripe-url "https://api.com/"}))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment