Skip to content

Commit

Permalink
feat(setup): add hello-world example
Browse files Browse the repository at this point in the history
  • Loading branch information
camwest committed Apr 25, 2016
1 parent 3e7f766 commit 46f9566
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(defproject chargepoint-rest-mock "0.1.0-SNAPSHOT"
:description "Fake REST API for http://chargepoint.com REST API"
:url "https://github.com/camwest/chargepoint-rest-mock"
:license {:name "The MIT license"
:url "https://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.8.0"]
[compojure "1.5.0"]
[ring/ring-defaults "0.2.0"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler chargepoint-rest-mock.core/app}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.0"]]}})
11 changes: 11 additions & 0 deletions src/chargepoint_rest_mock/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns chargepoint-rest-mock.core
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]))

(defroutes app-routes
(GET "/" [] "Hello World")
(route/not-found "Not found"))

(def app
(wrap-defaults app-routes api-defaults))
14 changes: 14 additions & 0 deletions test/chargepoint_rest_mock/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns chargepoint-rest-mock.core-test
(:require [clojure.test :refer :all]
[ring.mock.request :as mock]
[chargepoint-rest-mock.core :refer :all]))

(deftest test-app
(testing "main route"
(let [response (app (mock/request :get "/"))]
(is (= (:status response) 200))
(is (= (:body response) "Hello World"))))

(testing "not-found route"
(let [response (app (mock/request :get "/invalid"))]
(is (= (:status response) 404)))))

0 comments on commit 46f9566

Please sign in to comment.