Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #54 from duck1123/feature/route-testing
Convert all route tests to match the same pattern
- Loading branch information
Showing
15 changed files
with
147 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(ns jiksnu.modules.web.routes.activity-routes-test | ||
(:require [ciste.sections.default :refer [full-uri]] | ||
[clj-factory.core :refer [fseq]] | ||
[clojure.data.json :as json] | ||
[clojurewerkz.support.http.statuses :as status] | ||
[jiksnu.mock :as mock] | ||
[jiksnu.model.activity :as model.activity] | ||
jiksnu.modules.web.routes.activity-routes | ||
[jiksnu.routes-helper :refer [as-user json-response response-for]] | ||
[jiksnu.test-helper :as th] | ||
[jiksnu.util :as util] | ||
[midje.sweet :refer :all] | ||
[ring.mock.request :as req] | ||
[jiksnu.actions.activity-actions :as actions.activity])) | ||
|
||
(future-fact "apply-view #'actions.activity/oembed [:http :json]" | ||
(let [action #'actions.activity/oembed] | ||
(with-context [:http :json] | ||
(let [activity (mock/there-is-an-activity) | ||
request {:params {:url (:id activity)} | ||
:action action} | ||
response (filter-action action request)] | ||
(apply-view request response) => | ||
(contains {:status status/success? | ||
:body (contains {:title (:title activity)})}))))) | ||
|
||
(future-fact "apply-view #'actions.activity/oembed [:http :xml]" | ||
(let [action #'actions.activity/oembed] | ||
(with-context [:http :xml] | ||
(let [activity (mock/there-is-an-activity) | ||
request {:params {:url (:id activity)} | ||
:action action} | ||
item {} #_(filter-action action request)] | ||
(let [response (apply-view request item)] | ||
(let [body (:body response)] | ||
response => map? | ||
(:status response) => status/success? | ||
body =not=> string?)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
(ns jiksnu.modules.web.routes.home-routes-test | ||
(:require [ciste.formats :refer [format-as]] | ||
[ciste.model :as cm] | ||
[clojurewerkz.support.http.statuses :as status] | ||
[jiksnu.db :as db] | ||
[jiksnu.mock :as mock] | ||
[jiksnu.test-helper :as th] | ||
[jiksnu.routes-helper :refer [as-user response-for]] | ||
[midje.sweet :refer :all] | ||
[ring.mock.request :as req])) | ||
|
||
(th/module-test ["jiksnu.modules.core" | ||
"jiksnu.modules.web"]) | ||
|
||
(fact "route: root/home :get" | ||
(fact "when there are no activities" | ||
(db/drop-all!) | ||
|
||
|
||
(-> (req/request :get "/") | ||
response-for) => | ||
(contains {:status status/success?})) | ||
|
||
(fact "when there are activities" | ||
(let [user (mock/a-user-exists)] | ||
(dotimes [n 10] | ||
(mock/there-is-an-activity {:user user})) | ||
|
||
(fact "when the user is not authenticated" | ||
(-> (req/request :get "/") | ||
response-for) => | ||
(contains {:status status/success? | ||
:body string?})) | ||
|
||
(fact "when the user is authenticated" | ||
(-> (req/request :get "/") | ||
as-user response-for) => | ||
(contains {:status status/success? | ||
:body string?}))))) | ||
|
||
(future-fact "route: root/oembed :get" | ||
(fact "when the format is json" | ||
(let [activity (mock/there-is-an-activity) | ||
url (str "/main/oembed?format=json&url=" (:url activity))] | ||
(response-for (req/request :get url)) => | ||
(contains {:status status/redirect? | ||
:body string?}))) | ||
|
||
(fact "when the format is xml" | ||
(let [activity (mock/there-is-an-activity) | ||
url (str "/main/oembed?format=xml&url=" (:url activity))] | ||
(response-for (req/request :get url)) => | ||
(contains {:status status/success? | ||
:body string?})))) | ||
|
||
(future-fact "route: root/rsd :get" | ||
(let [response (-> (req/request :get "/rsd.xml") response-for)] | ||
response => map? | ||
(:status response) => status/success? | ||
(let [body (cm/string->document (:body response)) | ||
root (.getRootElement body) | ||
attr {"rsd" "http://archipelago.phrasewise.com/rsd"} | ||
nodes (cm/query root "//rsd:rsd" attr)] | ||
(count nodes) => 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
test/jiksnu/modules/web/routes/request_token_routes_test.clj
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters