Skip to content

Commit

Permalink
add tests for nullable and non-nullable variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Scherer committed May 15, 2017
1 parent 1d5c319 commit c992358
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions test/alumbra/canonicalizer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,41 @@
(if variables
(analyzer/canonicalize-operation schema ast nil variables)
(analyzer/canonicalize-operation schema ast))))]
(is (= (canonicalize
"{ randomCat(q: {emotions: [HAPPY HAPPIER]}) { name } }")
(canonicalize
"query ($q: CatQuery!) { randomCat(q: $q) { name } }"
{"q" {"emotions" ["HAPPY" "HAPPIER"]}})
(canonicalize
"query ($q: CatQuery = {emotions: [HAPPY HAPPIER]}) {
(testing "default value."
(is (= (canonicalize
"{ randomCat(q: {emotions: [HAPPY HAPPIER]}) { name } }")
(canonicalize
"query ($q: CatQuery!) { randomCat(q: $q) { name } }"
{"q" {"emotions" ["HAPPY" "HAPPIER"]}})
(canonicalize
"query ($q: CatQuery = {emotions: [HAPPY HAPPIER]}) {
randomCat(q: $q) { name }
}")))
(is (= (canonicalize
"{ randomCat(q: null) { name } }")
(canonicalize
"query ($q: CatQuery) { randomCat(q: $q) { name } }"
{"q" nil})
(canonicalize
"query ($q: CatQuery = {emotions: [HAPPY HAPPIER]}) {
randomCat(q: $q) { name }
}"
{"q" nil})))))
}"))))
(testing "explicit null value."
(is (= (canonicalize
"{ randomCat(q: null) { name } }")
(canonicalize
"query ($q: CatQuery) { randomCat(q: $q) { name } }"
{"q" nil})
(canonicalize
"query ($q: CatQuery = {emotions: [HAPPY HAPPIER]}) {
randomCat(q: $q) { name }
}"
{"q" nil}))))
(testing "nullable variable."
(let [query "query ($q: CatQuery) { randomCat(q: $q) { name } }"]
(is (= (canonicalize query {})
(canonicalize query {"q" nil})))))
(testing "non-nullable variable."
(let [query "query ($q: CatQuery!) { randomCat(q: $q) { name } }"]
(is (thrown-with-msg?
IllegalArgumentException
#"null value not allowed"
(canonicalize query {})))
(is (thrown-with-msg?
IllegalArgumentException
#"null value not allowed"
(canonicalize query {"q" nil})))))))

(deftest t-variable-type-mismatch
(letfn [(canonicalize [query variables]
Expand Down

0 comments on commit c992358

Please sign in to comment.