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}))) (resp/redirect (path :instance-edit-form {:uuid uuid})))
(route-link-selection! uuid schema-uuid req)))) (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] (defn route-delete-link! [uuid link-uuid]
(domain-link/delete! link-uuid) (domain-link/delete! link-uuid)
(resp/redirect (path :instance-edit-form {:uuid uuid}))) (resp/redirect (path :instance-edit-form {:uuid uuid})))

@ -6,13 +6,18 @@
[wanijo.schema.routes :as schema-routes] [wanijo.schema.routes :as schema-routes]
[wanijo.attribute.routes :as attr-routes] [wanijo.attribute.routes :as attr-routes]
[wanijo.instance.routes :as inst-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] (defn single-result
([cypher]
(single-result cypher
#(val (first %))))
([cypher extractor]
(extractor (extractor
(first (first
(neo4j/exec-query! (neo4j/exec-query!
(drv/create-query cypher) {})))) (drv/create-query cypher) {})))))
(defn multi-results [cypher extractor] (defn multi-results [cypher extractor]
(extractor (extractor
@ -34,11 +39,11 @@
(is (not= nil (:created_at schema))) (is (not= nil (:created_at schema)))
(is (= (:uuid user) (is (= (:uuid user)
(single-result "MATCH (s:schema)-[:created_by]->(u:user) (single-result "MATCH (s:schema)-[:created_by]->(u:user)
RETURN u.uuid AS uuid" :uuid))) RETURN u.uuid")))
(is (= (:uuid user) (is (= (:uuid user)
(single-result "MATCH (s:schema) (single-result "MATCH (s:schema)
<-[:permission {type:'write'}]-(u:user) <-[:permission {type:'write'}]-(u:user)
RETURN u.uuid AS uuid" :uuid)))) RETURN u.uuid"))))
(testing "create attribute" (testing "create attribute"
(attr-routes/new! {:params {:schema (:uuid schema) (attr-routes/new! {:params {:schema (:uuid schema)
@ -47,16 +52,16 @@
:required "1"} :required "1"}
:session {:uuid (:uuid user)}}) :session {:uuid (:uuid user)}})
(def attr (def attr
(single-result "MATCH (a:attribute) RETURN a" :a)) (single-result "MATCH (a:attribute) RETURN a"))
(is (= "string" (:type attr))) (is (= "string" (:type attr)))
(is (= "test-attr" (:name attr))) (is (= "test-attr" (:name attr)))
(is (= 1 (:required attr))) (is (= 1 (:required attr)))
(is (= (:uuid user) (is (= (:uuid user)
(single-result "MATCH (a:attribute)-[:created_by]->(u:user) (single-result "MATCH (a:attribute)-[:created_by]->(u:user)
RETURN u.uuid AS uuid" :uuid))) RETURN u.uuid")))
(is (= (:uuid schema) (is (= (:uuid schema)
(single-result "MATCH (a:attribute)-[:of]->(s:schema) (single-result "MATCH (a:attribute)-[:of]->(s:schema)
RETURN s.uuid AS uuid" :uuid)))) RETURN s.uuid"))))
(testing "assign read" (testing "assign read"
(schema-routes/assign-users! {:params {:uuid (:uuid schema) (schema-routes/assign-users! {:params {:uuid (:uuid schema)
@ -69,12 +74,56 @@
#(map (juxt :type :uuid) %))))) #(map (juxt :type :uuid) %)))))
(testing "create instance" (testing "create instance"
(inst-routes/route-new! {:params {:schema-uuid (:uuid schema) (inst-routes/route-new!
{:params {:schema-uuid (:uuid schema)
:name "instance" :name "instance"
(inst-forms/attr->field-id attr) "attr-value"} (inst-forms/attr->field-id attr) "attr-value"}
:session {:uuid (:uuid user)}}) :session {:uuid (:uuid user)}})
(def instance (def instance
(single-result "MATCH (i:instance) RETURN i" :i)) (single-result "MATCH (i:instance) RETURN i"))
(is (= "attr-value" (is (= "attr-value"
(single-result "MATCH (p:property) RETURN p.value AS value" (single-result "MATCH (p:property) RETURN p.value")))
: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