add tests for linking

alfred
Josha von Gizycki 4 years ago committed by Josha von Gizycki
parent 3b8e6f196a
commit 5c7f578704

@ -107,6 +107,11 @@
(resp/redirect (path :instance-edit-form {:uuid uuid})))
(route-link-selection! uuid schema-uuid req))))
(comment
(form/valid? (link-form! "6e7009e3-724b-4fce-afe0-7cf50f0bfcff")
{:params {:name "link-name"
:instances ["4bb90cc3-54d1-4d7d-bc30-c357777613ef"]}}))
(defn route-delete-link! [uuid link-uuid]
(domain-link/delete! link-uuid)
(resp/redirect (path :instance-edit-form {:uuid uuid})))
@ -141,14 +146,14 @@
(let [names (-> req :params :name)
instances (-> req :params :instances)
source-uuid (-> req :params :source-uuid)]
; (clojure.pprint/pprint names)
; (clojure.pprint/pprint instances)
; (clojure.pprint/pprint source-uuid)
#_ (clojure.pprint/pprint
(map (fn [[target-schema target-instances]]
{:link-name (get names target-schema)
:instances target-instances})
instances)))
; (clojure.pprint/pprint names)
; (clojure.pprint/pprint instances)
; (clojure.pprint/pprint source-uuid)
#_ (clojure.pprint/pprint
(map (fn [[target-schema target-instances]]
{:link-name (get names target-schema)
:instances target-instances})
instances)))
(resp/redirect (path :instance-show {:uuid uuid})))
(defn schema-uuid-by-instance [req]
@ -161,82 +166,82 @@
(def linking-routes
(-> (compojure/routes
(GET (register! :instance-link-selection
(GET (register! :instance-link-selection
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(route-link-selection! uuid schema-uuid req))
(POST (register! :instance-link-create
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(route-link-selection! uuid schema-uuid req))
(POST (register! :instance-link-create
"/instance/:uuid/link/:schema-uuid")
[uuid schema-uuid :as req]
(route-create-link! uuid schema-uuid req)))
(route-create-link! uuid schema-uuid req)))
(wrap-routes
(middleware-schema/wrap-allowed-to-write!
#(get-in % [:params :schema-uuid])))
(middleware-schema/wrap-allowed-to-write!
#(get-in % [:params :schema-uuid])))
(wrap-routes
(middleware-schema/wrap-allowed-to-write!
schema-uuid-by-instance))))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-by-instance))))
(def writing-routes-with-uuid-in-path
(wrap-routes
(compojure/routes
(GET (register! :instance-edit-form "/instance/:uuid/edit")
[uuid :as req]
(route-edit-form! uuid req))
(POST (register! :instance-edit "/instance/:uuid")
[uuid :as req]
(route-edit! uuid req))
(DELETE (register! :instance-delete "/instance/:uuid")
[uuid]
(route-delete! uuid))
(DELETE (register! :instance-link-delete
"/instance/:uuid/link/:link-uuid")
[uuid link-uuid]
(route-delete-link! uuid link-uuid))
(POST (register! :instance-mark-starred
(compojure/routes
(GET (register! :instance-edit-form "/instance/:uuid/edit")
[uuid :as req]
(route-edit-form! uuid req))
(POST (register! :instance-edit "/instance/:uuid")
[uuid :as req]
(route-edit! uuid req))
(DELETE (register! :instance-delete "/instance/:uuid")
[uuid]
(route-delete! uuid))
(DELETE (register! :instance-link-delete
"/instance/:uuid/link/:link-uuid")
[uuid link-uuid]
(route-delete-link! uuid link-uuid))
(POST (register! :instance-mark-starred
"/instance/:uuid/starred")
[uuid :as req]
(route-mark-starred! uuid req))
(DELETE (register! :instance-remove-starred
"/instance/:uuid/starred")
[uuid :as req]
(route-mark-starred! uuid req))
(DELETE (register! :instance-remove-starred
"/instance/:uuid/starred")
[uuid :as req]
(route-remove-starred! uuid req))
(GET (register! :instance-bulk-link-selection "/instance/:uuid/bulk-link")
[uuid :as req]
(route-bulk-link-selection! uuid req))
(POST (register! :instance-bulk-link-create "/instance/:uuid/bulk-link")
[uuid :as req]
(route-create-bulk-link! uuid req)))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-by-instance)))
(route-remove-starred! uuid req))
(GET (register! :instance-bulk-link-selection "/instance/:uuid/bulk-link")
[uuid :as req]
(route-bulk-link-selection! uuid req))
(POST (register! :instance-bulk-link-create "/instance/:uuid/bulk-link")
[uuid :as req]
(route-create-bulk-link! uuid req)))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-by-instance)))
(defroutes routes
;; read routes with :schema-uuid
(wrap-routes
(compojure/routes
(GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req]
(route-list! schema-uuid req)))
(middleware-schema/wrap-allowed-to-read!
schema-uuid-from-params))
(compojure/routes
(GET (register! :instance-list "/instance/list/:schema-uuid")
[schema-uuid :as req]
(route-list! schema-uuid req)))
(middleware-schema/wrap-allowed-to-read!
schema-uuid-from-params))
(wrap-routes
(compojure/routes
(GET (register! :instance-show "/instance/:uuid")
[uuid :as req]
(route-show! uuid req)))
(middleware-schema/wrap-allowed-to-read!
schema-uuid-by-instance))
(compojure/routes
(GET (register! :instance-show "/instance/:uuid")
[uuid :as req]
(route-show! uuid req)))
(middleware-schema/wrap-allowed-to-read!
schema-uuid-by-instance))
(wrap-routes
(compojure/routes
(POST (register! :instance-new "/instance/new") []
route-new!))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-from-params))
(compojure/routes
(POST (register! :instance-new "/instance/new") []
route-new!))
(middleware-schema/wrap-allowed-to-write!
schema-uuid-from-params))
linking-routes
writing-routes-with-uuid-in-path
(GET (register! :instance-list-starred "/instance/starred/list")
[:as req]
;; at some point someone will star an instance and then permissions to
;; the schema will be revoked
;; the instances will still be visible but can't be opened anymore
;; because of missing permissions, so they can't be unstared anymore
;; at some point someone will star an instance and then permissions to
;; the schema will be revoked
;; the instances will still be visible but can't be opened anymore
;; because of missing permissions, so they can't be unstared anymore
(route-list-starred! req)))

@ -6,13 +6,18 @@
[wanijo.schema.routes :as schema-routes]
[wanijo.attribute.routes :as attr-routes]
[wanijo.instance.routes :as inst-routes]
[wanijo.instance.forms :as inst-forms]))
[wanijo.instance.forms :as inst-forms]
[wanijo.instance.db :as inst-db]))
(defn single-result [cypher extractor]
(extractor
(first
(neo4j/exec-query!
(drv/create-query cypher) {}))))
(defn single-result
([cypher]
(single-result cypher
#(val (first %))))
([cypher extractor]
(extractor
(first
(neo4j/exec-query!
(drv/create-query cypher) {})))))
(defn multi-results [cypher extractor]
(extractor
@ -34,11 +39,11 @@
(is (not= nil (:created_at schema)))
(is (= (:uuid user)
(single-result "MATCH (s:schema)-[:created_by]->(u:user)
RETURN u.uuid AS uuid" :uuid)))
RETURN u.uuid")))
(is (= (:uuid user)
(single-result "MATCH (s:schema)
<-[:permission {type:'write'}]-(u:user)
RETURN u.uuid AS uuid" :uuid))))
RETURN u.uuid"))))
(testing "create attribute"
(attr-routes/new! {:params {:schema (:uuid schema)
@ -47,16 +52,16 @@
:required "1"}
:session {:uuid (:uuid user)}})
(def attr
(single-result "MATCH (a:attribute) RETURN a" :a))
(single-result "MATCH (a:attribute) RETURN a"))
(is (= "string" (:type attr)))
(is (= "test-attr" (:name attr)))
(is (= 1 (:required attr)))
(is (= (:uuid user)
(single-result "MATCH (a:attribute)-[:created_by]->(u:user)
RETURN u.uuid AS uuid" :uuid)))
RETURN u.uuid")))
(is (= (:uuid schema)
(single-result "MATCH (a:attribute)-[:of]->(s:schema)
RETURN s.uuid AS uuid" :uuid))))
RETURN s.uuid"))))
(testing "assign read"
(schema-routes/assign-users! {:params {:uuid (:uuid schema)
@ -69,12 +74,56 @@
#(map (juxt :type :uuid) %)))))
(testing "create instance"
(inst-routes/route-new! {:params {:schema-uuid (:uuid schema)
:name "instance"
(inst-forms/attr->field-id attr) "attr-value"}
:session {:uuid (:uuid user)}})
(inst-routes/route-new!
{:params {:schema-uuid (:uuid schema)
:name "instance"
(inst-forms/attr->field-id attr) "attr-value"}
:session {:uuid (:uuid user)}})
(def instance
(single-result "MATCH (i:instance) RETURN i" :i))
(single-result "MATCH (i:instance) RETURN i"))
(is (= "attr-value"
(single-result "MATCH (p:property) RETURN p.value AS value"
:value)))))
(single-result "MATCH (p:property) RETURN p.value")))
(is (= (:uuid user)
(single-result "MATCH (i:instance)-[:created_by]->(u:user)
RETURN u.uuid")))
(let [full-inst (inst-db/full-instance-by-uuid! (:uuid instance))]
(is (= "attr-value"
(-> full-inst :properties first :value)))
(is (= (:uuid attr)
(-> full-inst :properties first :attribute :uuid)))
(is (empty? (:tags full-inst)))
(is (empty? (:links-in full-inst)))
(is (empty? (:links-out full-inst)))))
(testing "create second instance and linking"
(inst-routes/route-new!
{:params {:schema-uuid (:uuid schema)
:name "instance2"
(inst-forms/attr->field-id attr) "attr-value2"}
:session {:uuid (:uuid user)}})
(def instance2
(single-result "MATCH (i:instance)
WITH MAX(i.created_at) AS max_created_at
MATCH (i:instance)
WHERE i.created_at = max_created_at
RETURN i"))
(is (= "instance2" (:name instance2)))
(inst-routes/route-create-link!
(:uuid instance)
(:uuid schema)
{:params {:name "link-name"
:instances [(:uuid instance2)]}
:session {:uuid (:uuid user)}})
(let [link (single-result "MATCH ()-[l:link]-() RETURN l")]
(is (= "link-name" (:name link)))
(is (= (:uuid user) (:created_by link)))
(is (some? (:created_at link))))
(is (= (:uuid instance)
(single-result "MATCH (i:instance)-[:link]->(:instance)
RETURN i.uuid")))
(is (= (:uuid instance2)
(single-result "MATCH (i:instance)<-[:link]-(:instance)
RETURN i.uuid")))))

Loading…
Cancel
Save