mirror of
https://github.com/zhigang1992/graphql-engine.git
synced 2026-06-15 10:07:56 +08:00
* add new optional field `claims_namespace_path` in JWT config * return value when empty array is found in executeJSONPath * update the docs related to claims_namespace_path * improve encodeJSONPath, add property tests for parseJSONPath * throw error if both claims_namespace_path and claims_namespace are set * refactor the Data.Parser.JsonPath to Data.Parser.JSONPathSpec * update the JWT docs Co-Authored-By: Marion Schleifer <marion@hasura.io> Co-authored-by: Marion Schleifer <marion@hasura.io> Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com> Co-authored-by: Tirumarai Selvan <tirumarai.selvan@gmail.com>
32 lines
1.1 KiB
Haskell
32 lines
1.1 KiB
Haskell
module Data.Parser.JSONPathSpec (spec) where
|
|
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types (encodeJSONPath)
|
|
|
|
import Data.Parser.JSONPath
|
|
import Test.Hspec
|
|
import Test.QuickCheck
|
|
|
|
import qualified Data.Text as T
|
|
|
|
spec :: Spec
|
|
spec = describe "parseJSONPath" $
|
|
it "JSONPath parser" $
|
|
withMaxSuccess 1000 $
|
|
forAll(resize 20 generateJSONPath) $ \jsonPath ->
|
|
let encPath = encodeJSONPath jsonPath
|
|
parsedJSONPathE = parseJSONPath $ T.pack encPath
|
|
in case parsedJSONPathE of
|
|
Left err -> counterexample (err <> ": " <> encPath) False
|
|
Right parsedJSONPath -> property $ parsedJSONPath == jsonPath
|
|
|
|
generateJSONPath :: Gen JSONPath
|
|
generateJSONPath = map (either id id) <$> listOf1 genPathElementEither
|
|
where
|
|
genPathElementEither = do
|
|
indexLeft <- Left <$> genIndex
|
|
keyRight <- Right <$> genKey
|
|
elements [indexLeft, keyRight]
|
|
genIndex = Index <$> choose (0, 100)
|
|
genKey = (Key . T.pack) <$> listOf1 (elements $ alphaNumerics ++ ".,!@#$%^&*_-?:;|/\"")
|