diff --git a/test/venia/spec_test.cljc b/test/venia/spec_test.cljc index be94b99..44639d0 100644 --- a/test/venia/spec_test.cljc +++ b/test/venia/spec_test.cljc @@ -5,31 +5,39 @@ [clojure.test :refer :all]))) (deftest query->spec-simple-query - "Simple vector queries" - (testing "Empty vector, should not be valid" + (testing "Wrong data type - vector instead of map, should throw exception" (is (thrown? #?(:clj Exception :cljs js/Error) (vs/query->spec [])))) - (testing "Vector has only query name, should not be valid" + (testing "Correct data type, but map is empty, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [[:queryName]])))) - (testing "Vector has only fields, should not be valid" + :cljs js/Error) (vs/query->spec {})))) + (testing ":venia/queries is missing, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [[[:x :y]]])))) - (testing "Vector has non-keyword query name, should not be valid" + :cljs js/Error) (vs/query->spec {:venia/operation {:operation/name "operation" :operation/type :query}})))) + (testing ":venia/queries has wrong type - map instead of vector, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [["queryName" {:id 1} [:x :y]]])))) - (testing "Vector has query name and args, but no fields. Should not be valid" + :cljs js/Error) (vs/query->spec {:venia/queries {}})))) + (testing ":venia/queries is empty, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [[:queryName {:id 1}]])))) - (testing "Vector has args in wrong format, should not be valid" + :cljs js/Error) (vs/query->spec {:venia/queries []})))) + (testing "Query vector has only query name, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [[:queryName [:id 1] [:x :y]]])))) - (testing "Vector has fields in wrong format, should not be valid" + :cljs js/Error) (vs/query->spec {:venia/queries [[:queryName]]})))) + (testing "Query vector has only fields, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [[:queryName {:id 1} {:x :y}]])))) - (testing "Inner vector missing, should not be valid" + :cljs js/Error) (vs/query->spec (vs/query->spec {:venia/queries [[[:x :y]]]}))))) + (testing "Query vector has non-keyword query name, should throw exception" (is (thrown? #?(:clj Exception - :cljs js/Error) (vs/query->spec [[:queryName {:id 1} [:x :y]]])))) + :cljs js/Error) (vs/query->spec (vs/query->spec {:venia/queries [["queryName" {:id 1} [:x :y]]]}))))) + (testing "Query vector has query name and args, but no fields. Should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec (vs/query->spec {:venia/queries [[:queryName {:id 1}]]}))))) + (testing "Query vector has args in wrong format, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/queries [[:queryName [:id 1] [:x :y]]]})))) + (testing "Query vector has fields in wrong format, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/queries [[[:queryName {:id 1} {:x :y}]]]})))) (testing "Valid vector with single query, should return conformed data" (is (= [:venia/query-def {:venia/queries [[:query/data {:query :employee :args {:id 1 :active true} @@ -38,6 +46,31 @@ :venia/nested-field-children [[:venia/field :name] [:venia/field :email]]}]]}]]}] (vs/query->spec {:venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) + (testing ":venia/operation is missing name, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/operation {:operation/type :query} + :venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) + (testing ":venia/operation is missing type, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/operation {:operation/name "name"} + :venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) + (testing ":venia/operation has type, which is not supported, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/operation {:operation/type :mutation} + :venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) + + (testing ":venia/variables is empty, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/variables [] + :venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) + (testing ":venia/variables is missing name, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/variables [{:variable/type :query}] + :venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) + (testing ":venia/variables is missing type, should throw exception" + (is (thrown? #?(:clj Exception + :cljs js/Error) (vs/query->spec {:venia/variables [{:variable/name "name"}] + :venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})))) (testing "Valid vector with all possible data, should return conformed data" (is (= [:venia/query-def {:venia/operation {:operation/type :query :operation/name "employeeQuery"}