add instance test

alfred
Josha von Gizycki 3 years ago committed by Josha von Gizycki
parent bc0585f772
commit 3b8e6f196a

@ -4,7 +4,9 @@
[wanijo.infra.neo4j :as neo4j]
[wanijo.infra.repl :as repl]
[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.forms :as inst-forms]))
(defn single-result [cypher extractor]
(extractor
@ -12,6 +14,11 @@
(neo4j/exec-query!
(drv/create-query cypher) {}))))
(defn multi-results [cypher extractor]
(extractor
(neo4j/exec-query!
(drv/create-query cypher) {})))
(deftest allround-system-test
(repl/setup-in-memory!)
(def user
@ -24,10 +31,14 @@
(def schema
(single-result "MATCH (s:schema) RETURN s LIMIT 1" :s))
(is (= "test-schema" (:name schema)))
(is (not= nil (:created_at schema)))
(is (= (:uuid user)
(single-result "MATCH (s:schema)-[:created_by]->(u:user)
RETURN u.uuid AS uuid" :uuid)))
(is (not= nil (:created_at schema))))
(is (= (:uuid user)
(single-result "MATCH (s:schema)
<-[:permission {type:'write'}]-(u:user)
RETURN u.uuid AS uuid" :uuid))))
(testing "create attribute"
(attr-routes/new! {:params {:schema (:uuid schema)
@ -45,4 +56,25 @@
RETURN u.uuid AS uuid" :uuid)))
(is (= (:uuid schema)
(single-result "MATCH (a:attribute)-[:of]->(s:schema)
RETURN s.uuid AS uuid" :uuid)))))
RETURN s.uuid AS uuid" :uuid))))
(testing "assign read"
(schema-routes/assign-users! {:params {:uuid (:uuid schema)
:assigned [(:uuid user)]
:permission "read"}})
(is (= (list ["read" (:uuid user)] ["write" (:uuid user)])
(multi-results "MATCH (s:schema)
<-[p:permission]-(u:user)
RETURN p.type AS type, u.uuid AS uuid"
#(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)}})
(def instance
(single-result "MATCH (i:instance) RETURN i" :i))
(is (= "attr-value"
(single-result "MATCH (p:property) RETURN p.value AS value"
:value)))))

Loading…
Cancel
Save