From 3b8e6f196a773ae6b3efb4d9620ba1ba40fb10e4 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 14 Mar 2021 17:43:51 +0100 Subject: [PATCH] add instance test --- test/wanijo/infra/system_test.clj | 38 ++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/test/wanijo/infra/system_test.clj b/test/wanijo/infra/system_test.clj index a4c1c9e..6b51a06 100644 --- a/test/wanijo/infra/system_test.clj +++ b/test/wanijo/infra/system_test.clj @@ -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)))))