-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organise create-draftsets out of draftset-api into feature layout
- Loading branch information
1 parent
294efba
commit 5d491f1
Showing
6 changed files
with
104 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,27 @@ | ||
(ns drafter.feature.draftset.create) | ||
(ns drafter.feature.draftset.create | ||
(:require [drafter.backend.draftset.operations :as dsops] | ||
[drafter.feature.common :as feat-common] | ||
[drafter.rdf.draftset-management.job-util :as jobutil] | ||
[drafter.util :as util] | ||
[ring.util.response :as ring] | ||
[swirrl-server.responses :as response])) | ||
|
||
(defn create-draftsets-handler [{wrap-authenticated :wrap-auth backend :drafter/backend}] | ||
(let [version "/v1"] | ||
(wrap-authenticated | ||
(fn [{{:keys [display-name description]} :params user :identity :as request}] | ||
(feat-common/run-sync #(dsops/create-draftset! backend user display-name description util/create-uuid util/get-current-time) | ||
(fn [result] | ||
(if (jobutil/failed-job-result? result) | ||
(response/api-response 500 result) | ||
(ring/redirect-after-post (str version "/draftset/" | ||
(get-in result [:details :id])))))))))) | ||
|
||
(s/def ::wrap-auth fn?) | ||
|
||
(defmethod ig/pre-init-spec ::handler [_] | ||
(s/keys :req [:drafter/backend] :req-un [::wrap-auth])) | ||
|
||
(defmethod ig/init-key ::handler [_ opts] | ||
(create-draftsets-handler opts)) | ||
|
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 |
---|---|---|
@@ -1,4 +1,71 @@ | ||
(ns drafter.feature.draftset.create-test | ||
(:require [drafter.feature.draftset.create :as sut] | ||
[clojure.test :as t])) | ||
[clojure.test :as t]) | ||
(:require [clojure.java.io :as io] | ||
[clojure.set :as set] | ||
[clojure.test :refer :all :as t] | ||
[drafter.middleware :as middleware] | ||
[drafter.rdf.drafter-ontology | ||
:refer | ||
[drafter:DraftGraph drafter:modifiedAt]] | ||
[drafter.rdf.draftset-management.job-util :as jobs] | ||
[drafter.rdf.sparql :as sparql] | ||
[drafter.swagger :as swagger] | ||
[drafter.test-common :as tc] | ||
[drafter.timeouts :as timeouts] | ||
[drafter.user :as user] | ||
[drafter.user-test :refer [test-editor test-manager test-password test-publisher]] | ||
[drafter.user.memory-repository :as memrepo] | ||
[drafter.util :as util] | ||
[grafter.rdf :refer [add context statements]] | ||
[grafter.rdf.protocols :refer [->Quad ->Triple map->Triple]] | ||
[grafter.rdf4j.formats :as formats] | ||
[grafter.rdf4j.io :refer [rdf-writer]] | ||
[schema.core :as s] | ||
[swirrl-server.async.jobs :refer [finished-jobs]])) | ||
|
||
(def see-other-response-schema | ||
(merge tc/ring-response-schema | ||
{:status (s/eq 303) | ||
:headers {(s/required-key "Location") s/Str}})) | ||
|
||
|
||
|
||
(defn assert-is-see-other-response [response] | ||
(tc/assert-schema see-other-response-schema response)) | ||
|
||
|
||
|
||
(defn valid-swagger-response? | ||
"Applies handler to request and validates the response against the | ||
swagger spec for the requested route. | ||
Returns the response if valid, otherwise raises an error." | ||
[handler request] | ||
(let [swagger-spec (swagger/load-spec-and-resolve-refs)] | ||
(swagger/validate-response-against-swagger-spec swagger-spec request (handler request)))) | ||
|
||
(defn create-draftset-request | ||
"Build a HTTP request object that representing a request to create a | ||
draftset." | ||
([] (create-draftset-request test-editor)) | ||
([user] (create-draftset-request user nil)) | ||
([user display-name] (create-draftset-request user display-name nil)) | ||
([user display-name description] | ||
(tc/with-identity user {:uri "/v1/draftsets" :request-method :post :params {:display-name display-name :description description}}))) | ||
|
||
(tc/deftest-system create-draftset-without-title-or-description | ||
[{handler :drafter.feature.draftset.create/handler} "test-system.edn"] | ||
(let [request (tc/with-identity test-editor {:uri "/v1/draftsets" :request-method :post}) | ||
response (valid-swagger-response? handler request)] | ||
(assert-is-see-other-response response))) | ||
|
||
(tc/deftest-system create-draftset-with-title-and-without-description | ||
[{handler :drafter.feature.draftset.create/handler} "test-system.edn"] | ||
(let [response (valid-swagger-response? handler (create-draftset-request test-editor "Test Title!"))] | ||
(assert-is-see-other-response response))) | ||
|
||
(tc/deftest-system create-draftset-with-title-and-description | ||
[{handler :drafter.feature.draftset.create/handler} "test-system.edn"] | ||
(let [response (valid-swagger-response? handler (create-draftset-request test-editor "Test title" "Test description"))] | ||
(assert-is-see-other-response response))) |
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